#include <bits/stdc++.h>
using namespace std;
int main() {
  int i, count = 0, seq_array[10] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
         num_array[10] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, max = 0;
  long long int num;
  string seq;
  cin >> num >> seq;
  do {
    if (num % 10 == 5) {
      num_array[2] += 1;
    } else if (num % 10 == 9) {
      num_array[6] += 1;
    } else
      num_array[num % 10] += 1;
    num = num / 10;
    count++;
  } while (num != 0);
  i = 0;
  do {
    if ((int(seq[i]) - 48) == 5) {
      seq_array[2] += 1;
    } else if ((int(seq[i]) - 48) == 9) {
      seq_array[6] += 1;
    } else
      seq_array[int(seq[i]) - 48] += 1;
    i++;
  } while (i <= seq.length());
  do {
    count = 0;
    for (i = 0; i < 10; i++) {
      if (num_array[i] != 0) {
        seq_array[i] = seq_array[i] - num_array[i];
        if (seq_array[i] < 0) {
          count = 1;
          break;
        }
      }
    }
    max++;
  } while (count != 1);
  cout << --max;
  return 0;
}
