#include <bits/stdc++.h>
using namespace std;
int a, c, i;
string b, d;
int main() {
  cin >> a >> b;
  for (c = a + 1;; c++) {
    for (i = c, d = ""; i > 0; i = i / 10) {
      if (i % 10 == 4 || i % 10 == 7) d = (char)(i % 10 + 48) + d;
    }
    if (d == b) break;
  }
  cout << c << endl;
}
