#include <bits/stdc++.h>
using namespace std;
string mask(int n) {
  string s = "";
  char c;
  while (n) {
    c = (n % 10) + '0';
    if (n % 10 == 4 || n % 10 == 7) s = c + s;
    n /= 10;
  }
  return s;
}
int main() {
  int a, b;
  cin >> a >> b;
  string s = mask(b);
  while (1) {
    a++;
    if (s == mask(a)) {
      cout << a << endl;
      return 0;
    }
  }
  return 0;
}
