#include <bits/stdc++.h>
using namespace std;
inline void out(int a) { printf("%d\n", a); }
inline void out(int a, int b) { printf("%d %d\n", a, b); }
inline void outf(double a) { printf("%3.lf\n", a); }
inline void outf(double a, double b) { printf("%3.lf %3.lf\n", a, b); }
inline void base() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
}
bool cek(long long a, long long b) {
  long long tmp = 0;
  long long ctr = 1;
  while (a) {
    if (a % 10 == 7 || a % 10 == 4) {
      tmp = tmp + ctr * (a % 10);
      ctr *= 10;
    }
    a /= 10;
  }
  return tmp == b;
}
int main() {
  base();
  long long a, b;
  cin >> a >> b;
  a++;
  while (!cek(a, b)) {
    a++;
  }
  cout << a << endl;
  return 0;
}
