#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e6;
inline void out(long long x) {
  if (x > 9) out(x / 10);
  putchar(x % 10 + '0');
}
void read(int &x) {
  char ch;
  bool flag = 0;
  for (ch = getchar(); !isdigit(ch) && ((flag |= (ch == '-')) || 1);
       ch = getchar())
    ;
  for (x = 0; isdigit(ch); x = (x << 1) + (x << 3) + ch - 48, ch = getchar())
    ;
  x *= 1 - 2 * flag;
}
int fun(int n) {
  vector<int> vec;
  while (n) {
    int temp = n % 10;
    if (temp == 4 || temp == 7) {
      vec.push_back(temp);
    }
    n /= 10;
  }
  int ans = 0;
  for (int i = vec.size() - 1; i >= 0; i--) {
    ans = ans * 10 + vec[i];
  }
  return ans;
}
int main() {
  int a, b;
  while (cin >> a >> b) {
    while (1) {
      a++;
      if (fun(a) == b) break;
    }
    cout << a << endl;
  }
  return 0;
}
