#include <bits/stdc++.h>
using namespace std;
bool f(int a, string s) {
  vector<char> v;
  int tmp;
  int ss = (s.size() - 1);
  while (a) {
    tmp = a % 10;
    if (tmp == 7) v.push_back('7');
    if (tmp == 4) v.push_back('4');
    a /= 10;
  }
  if (v.size() != s.size()) return false;
  for (int i = 0; i < s.size(); i++) {
    if (s[i] != v[s.size() - i - 1]) return false;
  }
  return true;
}
int main() {
  int a;
  string s;
  cin >> a >> s;
  for (int i = (a + 1); i <= 100000000; i++) {
    if (f(i, s)) {
      cout << i << endl;
      return 0;
    }
  }
}
