#include <bits/stdc++.h>
using namespace std;
int Arwa(long long x) {
  for (long long i = 2; i * i <= x; i++) {
    if (x % i == 0) return 0;
  }
  return 1;
}
string t_s(int x) {
  stringstream ss;
  ss << x;
  string y;
  ss >> y;
  return y;
}
void fara7a() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
}
using namespace std;
int main() {
  fara7a();
  int a, b, x = 0;
  cin >> a >> b;
  string s = t_s(b);
  while (1) {
    a++;
    string str = t_s(a), z = "";
    for (int i = 0; i < (int)str.size(); i++) {
      if (str[i] == '4' || str[i] == '7') z += str[i];
    }
    if (z == s) break;
  }
  cout << a << endl;
}
