#include <bits/stdc++.h>
using namespace std;
int main() {
  int a, b;
  cin >> a >> b;
  if (a < b)
    cout << b << endl;
  else {
    bool find = false;
    for (int i = a + 1; !find; ++i) {
      vector<int> v;
      int n = i;
      while (n != 0) {
        v.push_back(n % 10);
        n /= 10;
      }
      for (int j = v.size() - 1; j >= 0; --j)
        if (v[j] == 4 || v[j] == 7) n = n * 10 + v[j];
      if (n == b) {
        find = true;
        cout << i << endl;
      }
    }
  }
  return 0;
}
