#include <bits/stdc++.h>
using namespace std;
const double pi = acos(-1);
const long long mod = 1000000007;
int n, k;
bool ok(int a, int b) {
  string s1 = "", s2 = "";
  while (a) {
    s1 += ((a % 10) + '0');
    a /= 10;
  }
  while (b) {
    s2 += ((b % 10) + '0');
    b /= 10;
  }
  string check;
  for (int i = 0; i < (int)s1.size(); ++i)
    if (s1[i] == '4' || s1[i] == '7') check += s1[i];
  return s2 == check;
}
int main() {
  cin >> n >> k;
  for (int h = n + 1;; ++h) {
    if (ok(h, k)) return cout << h << endl, 0;
  }
  return 0;
}
