#include <bits/stdc++.h>
using namespace std;
int a, b;
bool check(int n) {
  int x = 0, n1 = n;
  string s = "";
  char c;
  while (n) {
    c = '0';
    if (n % 10 == 4 || n % 10 == 7) c = ((n % 10) + '0');
    n /= 10;
    if (c != '0') s.insert(s.begin(), c);
  }
  for (int i = 0; i < s.size(); i++) x *= 10, x += s[i] - '0';
  return x == b;
}
int main() {
  cin >> a >> b;
  int i = a + 1;
  while (!check(i)) i++;
  cout << i << endl;
}
