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

int main() {
  int N, K;
  cin >> N >> K;

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

  int ans = N;
  while (true) {
    bool f = false;
    int s = ans;
    while (s) {
      f |= dis[s % 10];
      s /= 10;
    }

    if (!f) break;
    ans++;
  }

  cout << ans << endl;
}
