#include <bits/stdc++.h>
using namespace std;
const int inf = 0x3f3f3f3f;
const double oo = 10e9;
const double eps = 10e-7;
int a, b;
vector<int> v;
inline int mask(int x) {
  v.clear();
  int temp;
  int now;
  while (x) {
    now = x % 10;
    if (now == 7 || now == 4) {
      v.push_back(now);
    }
    x /= 10;
  }
  temp = 0;
  while (!v.empty()) {
    temp *= 10;
    temp += v.back();
    v.pop_back();
  }
  return temp;
}
int find() {
  int temp;
  for (int i = a + 1;; i++) {
    temp = mask(i);
    if (temp == b) {
      return i;
    }
  }
  assert(false);
}
int main() {
  while (cin >> a >> b) {
    if (b > a) {
      cout << b << endl;
    } else {
      cout << find() << endl;
    }
  }
  return 0;
}
