#include <bits/stdc++.h>
using namespace std;
int main() {
  int a;
  string b;
  cin >> a >> b;
  while (a++) {
    int i = a;
    string comp = "";
    while (i > 0) {
      int c = i % 10;
      if (c == 4 || c == 7) {
        comp = to_string(c) + comp;
      }
      i /= 10;
    }
    if (comp == b) {
      cout << a;
      return 0;
    }
  }
}
