#include <bits/stdc++.h>
using namespace std;
long long mod_v(long long num) {
  if (num >= 0)
    return (num % 1000000007);
  else
    return (num % 1000000007 + 1000000007) % 1000000007;
}
long long bigmod(long long b, long long p, long long m) {
  long long res = 1 % m, x = b % m;
  while (p) {
    if (p & 1) res = (res * x) % m;
    x = (x * x) % m;
    p >>= 1;
  }
  return res;
}
bool check(int a, string b) {
  string str = "";
  while (a) {
    int r = a % 10;
    if (r == 4 || r == 7) {
      str += (char)(r + '0');
    }
    a = a / 10;
  }
  reverse(str.begin(), str.end());
  if (str == b)
    return true;
  else
    return false;
}
int main() {
  int a;
  string b;
  cin >> a >> b;
  while (1) {
    a++;
    if (check(a, b)) break;
  }
  printf("%d\n", a);
}
