#include <bits/stdc++.h>
const long long MAX = 1e11 + 111;
std::string num;
std::string val;
std::string plus(std::string s1, std::string s2) {
  if (s2.length() > s1.length()) {
    std::string swap = s1;
    s1 = s2;
    s2 = swap;
  }
  while (s2.length() < s1.length()) {
    s2 = '0' + s2;
  }
  std::string sum = "";
  long long length = s1.length();
  long long ex = 0;
  long long tmp = 0;
  for (long long i = length - 1; i >= 0; --i) {
    tmp = (s1[i] - '0') + (s2[i] - '0') + ex;
    ex = tmp / 10;
    tmp %= 10;
    sum = (char)(tmp + '0') + sum;
  }
  if (ex != 0) {
    sum = '1' + sum;
  }
  return sum;
}
bool cmpNumString(std::string s1, std::string s2) {
  if (s1.length() != s2.length()) return false;
  long long length = s1.length();
  for (long long i = 0; i < length; ++i)
    if (s1[i] != s2[i]) return false;
  return true;
}
long long min(long long a, long long b) { return (a < b) ? a : b; }
long long max(long long a, long long b) { return (a > b) ? a : b; }
signed main() {
  std::cin >> num;
  std::cin >> val;
  long long maxLength = val.length();
  for (long long i = maxLength; i > 0; --i) {
    std::string sum = "0";
    long long size = num.length() / i;
    if (num.length() % i != 0) ++size;
    for (long long j = 1; j <= size; ++j) {
      std::string tmp =
          num.substr(max(num.length() - i * j, 0),
                     num.length() - i * (j - 1) - max(num.length() - i * j, 0));
      sum = plus(sum, tmp);
    }
    if (cmpNumString(sum, val)) {
      std::cout << pow(10, i);
      return 0;
    }
  }
}
