#include <bits/stdc++.h>
using namespace std;
string obj;
bool solve(int x) {
  string s = to_string(x);
  string ans;
  for (int i = 0; i < s.size(); i++)
    if (s[i] == '7' || s[i] == '4') ans.push_back(s[i]);
  return ans == obj;
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int a, b;
  cin >> a >> b;
  obj = to_string(b);
  int i = a + 1;
  while (!solve(i)) i++;
  cout << i << "\n";
  return 0;
}
