#include <bits/stdc++.h>
using namespace std;
int main() {
  int x, y;
  cin >> x >> y;
  string k, s, q;
  stringstream aa;
  aa << y;
  aa >> s;
  if (x < y) {
    cout << y;
    return 0;
  } else {
    x = x + 1;
    while (true) {
      stringstream ss;
      ss << x;
      ss >> k;
      for (int i = 0; i < k.size(); i++) {
        if (k[i] == '7' || k[i] == '4') q += k[i];
      }
      if (q == s) {
        cout << x;
        return 0;
      } else
        x++;
      q = "";
    }
  }
}
