#include <bits/stdc++.h>
int main() {
  std::ios::sync_with_stdio(false);
  std::cin.tie(nullptr);
  std::string t;
  std::cin >> t;
  std::map<char, size_t> tc;
  for (char c : t) {
    if (c == '5') {
      c = '2';
    }
    if (c == '9') {
      c = '6';
    }
    tc[c] += 1;
  }
  std::string s;
  std::cin >> s;
  std::map<char, size_t> sc;
  for (char c : s) {
    if (c == '5') {
      c = '2';
    }
    if (c == '9') {
      c = '6';
    }
    sc[c] += 1;
  }
  size_t result = 0;
  for (;;) {
    bool ok = true;
    for (const auto& [k, v] : tc) {
      if (sc[k] >= v) {
        sc[k] -= v;
      } else {
        ok = false;
        break;
      }
    }
    if (!ok) {
      break;
    }
    result += 1;
  }
  std::cout << result << '\n';
}
