#include <bits/stdc++.h>
using namespace std;
int main() {
  vector<int> a(10, 0), b(10, 0);
  string n;
  string num;
  cin >> n >> num;
  for (auto w : num) {
    a[w - '0']++;
  }
  int minimum = INT_MAX;
  for (auto w : n) b[w - '0']++;
  for (int i = 0; i < 10; i++) {
    if (i != 2 && i != 6 && i != 5 && i != 9 && b[i] > 0)
      minimum = min(minimum, a[i] / b[i]);
  }
  if (b[2] + b[5] > 0) minimum = min(minimum, (a[2] + a[5]) / (b[2] + b[5]));
  if (b[6] + b[9] > 0) minimum = min(minimum, (a[6] + a[9]) / (b[6] + b[9]));
  cout << minimum;
  return 0;
}
