#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <string>
#include <cstring>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <cmath>
#include <functional>
#include <algorithm>
using namespace std;

const int N = 16;

int n, k;
char a[N], b[N], buf[N];

bool ok() {
  for(int i = 0; buf[i]; i++) if(b[buf[i]]) return false;
  return true;
}

int main() {
  cin >> n >> k;
  for(int i = 0; i < k; i++) scanf(" %c", &a[i]), b[a[i]] = true;
  sprintf(buf, "%d", n);
  while(!ok()) n++, sprintf(buf, "%d", n);
  cout << n << endl;
  return 0;
}
