#include <bits/stdc++.h>
using namespace std;

int main() {
  int n, k;
  cin >> n >> k;

  bool d[10] = {};
  for (int i = 0; i < k; ++i) {
    int D;
    cin >> D;
    d[D] = true;
  }

  for (int i = n;; ++i) {
    int t = i;
    bool f = true;
    while (t) {
      if (d[t % 10]) f = false;
      t /= 10;
    }

    if (f) {
      cout << i << endl;
      break;
    }
  }
}
