#include <bits/stdc++.h>
using namespace std;
int t[105];
int lucky(int n) {
  int ans = 0, temp = 1;
  while (n != 0) {
    if (n % 10 == 7 || n % 10 == 4) {
      ans += temp * (n % 10);
      temp *= 10;
    }
    n /= 10;
  }
  return ans;
}
int main() {
  int n, m;
  string s;
  int a, b;
  while (cin >> a >> b) {
    for (int i = a + 1;; i++) {
      if (lucky(i) == b) {
        printf("%d\n", i);
        break;
      }
    }
  }
}
