#include <bits/stdc++.h>
using namespace std;
int mask(int m) {
  int n = m;
  int ans = 0;
  int t = 1;
  while (n > 0) {
    if (n % 10 == 4 || n % 10 == 7) {
      ans += t * (n % 10);
      t *= 10;
    }
    n = n / 10;
  }
  return ans;
}
int main() {
  int a, b;
  while (cin >> a >> b) {
    a++;
    while (mask(a) != b) {
      a++;
    }
    cout << a << endl;
  }
  return 0;
}
