#include <bits/stdc++.h>
using namespace std;
void File_input(string pathIn) { freopen(pathIn.c_str(), "r", stdin); }
void File_output(string pathOut) { freopen(pathOut.c_str(), "w", stdout); }
int msg() {
  srand(time(0));
  vector<string> st = {"Wish everyone high ratings!", "Good luck!", "Have fun!",
                       "Please, read all the problems!", "Go Go fight!"};
  cerr << st[rand() % (int)st.size()];
  return 0;
}
void FastInputOutput() {
  ios_base ::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
}
int a, b;
bool ok = 0;
string st, mat;
int main() {
  cin >> a >> b;
  mat = to_string(b);
  for (int i = a + 1; !ok; i++) {
    st = to_string(i);
    int _4, _7;
    _4 = count(st.begin(), st.end(), '4');
    _7 = count(st.begin(), st.end(), '7');
    if (_4 + _7 == (int)mat.size()) {
      int be = 0;
      for (int j = 0; j < (int)st.size(); j++) {
        if (st[j] == mat[be]) {
          be++;
        }
      }
      if (be == (int)mat.size()) {
        ok = 1;
      }
    }
  }
  cout << st;
  return 0;
}
