#include<bits/stdc++.h>

using namespace std;

bool bad[10];

int main(){
  int n; cin >> n;
  int k; cin >> k;
  for(int i=0;i<k;i++){
    int t; cin >> t;
    bad[t] = true;
  }
  for(int e = n; ; e++){
    bool ok = true;
    int u = e;
    while(u != 0){
      int d = u % 10;
      if(bad[d]){ ok = false; break; }
      u /= 10;
    }
    if(ok){
      cout << e << "\n";
      return 0;
    }
  }
}
