#include <bits/stdc++.h>
using namespace std;
int f(int n) {
  int i = 0;
  int num = n, num1 = 1;
  while (n > 0) {
    n = n / 10;
    num1 = num1 * 10;
  }
  num1 = num1 / 10;
  int sum = 0;
  while (num > 0) {
    if (num / num1 == 4 || num / num1 == 7) {
      sum = sum * 10 + num / num1;
    }
    num = num % num1;
    num1 = num1 / 10;
  }
  return sum;
}
int main() {
  int a, b;
  cin >> a >> b;
  while (1) {
    a++;
    if (f(a) == b) {
      cout << a << endl;
      break;
    }
  }
  return (0);
}
