#include <bits/stdc++.h>
using namespace std;
int a;
string b;
bool luckyN() {
  stringstream ss;
  ss << a;
  stringstream s2;
  string s = ss.str();
  for (int i = 0; i < s.length(); i++)
    if (s[i] == '4' || s[i] == '7') s2 << s[i];
  string v = s2.str();
  if (b.length() != v.length()) return false;
  for (int i = 0; i < b.length(); i++)
    if (b[i] != v[i]) return false;
  return true;
}
int main() {
  std::ios::sync_with_stdio(0);
  cin.tie(0);
  cin >> a >> b;
  a++;
  while (!luckyN()) a++;
  cout << a << "\n";
  return 0;
}
