#include <bits/stdc++.h>
#pragma warning(disable : 4996)
using namespace std;
const int N = 1e5 + 10;
int Dx[] = {1, 0, -1, 0, 1, 1, -1, -1};
int Dy[] = {0, 1, 0, -1, 1, -1, 1, -1};
long long gcd(long long a, long long b) {
  if (b == 0) return a;
  return gcd(b, a % b);
}
long long powm(long long a, long long b) {
  long long res = 1;
  while (b > 0) {
    if (b % 2) res *= a;
    a *= a;
    b /= 2;
  }
  return res;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ;
  int a, b;
  cin >> a >> b;
  a++;
  int st = a, tem = 0, m = 1;
  while (4) {
    m = 1, tem = 0;
    while (a) {
      if (a % 10 == 4 || a % 10 == 7) {
        tem += m * (a % 10);
        m *= 10;
      }
      a /= 10;
    }
    if (tem == b) {
      cout << st;
      break;
    }
    a = ++st;
  }
  return 0;
}
