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