#include <bits/stdc++.h>
using namespace std;
int main() {
  int t, char_count;
  int t_count = 1;
  int array_of_numbers[10];
  int possobilities[10];
  for (int i = 0; i < 10; i++) {
    array_of_numbers[i] = 0;
    possobilities[i] = 0;
  }
  cin >> t;
  string s;
  cin >> s;
  char_count = s.length();
  for (int i = 0; i < char_count; i++) {
    array_of_numbers[s[i] - '0']++;
  }
  int tmp = t;
  while (tmp / 10 > 0) {
    t_count++;
    tmp = tmp / 10;
  }
  tmp = t;
  int sequence[10];
  for (int i = 0; i < 10; i++) {
    sequence[i] = 0;
  }
  for (int i = 0; i < t_count; i++) {
    sequence[tmp % 10]++;
    tmp = tmp / 10;
  }
  for (int i = 0; i < 10; i++) {
  }
  for (int i = 0; i < 10; i++) {
  }
  int minans;
  for (int i = 0; i < 10; i++) {
    if (i == 9 || i == 5) {
    } else {
      if (sequence[i] != 0 ||
          (sequence[i] == 0 && (i == 2 || i == 6) && sequence[i + 3] != 0)) {
        if (i != 6 && i != 2)
          possobilities[i] = array_of_numbers[i] / sequence[i];
        else if (i == 6) {
          possobilities[i] = (array_of_numbers[i] + array_of_numbers[9]) /
                             (sequence[i] + sequence[9]);
          possobilities[9] = possobilities[i];
        } else if (i == 2) {
          possobilities[i] = (array_of_numbers[i] + array_of_numbers[5]) /
                             (sequence[i] + sequence[5]);
          possobilities[5] = possobilities[i];
        }
      } else if (sequence[i] == 0) {
        possobilities[i] = -1;
        if ((i == 2 || i == 6) && sequence[i + 3] == 0)
          possobilities[i + 3] = -1;
      }
    }
    if (possobilities[i] > 0) minans = possobilities[i];
  }
  for (int i = 0; i < 10; i++) {
    if (possobilities[i] != -1) {
      if (minans > possobilities[i]) minans = possobilities[i];
    }
  }
  cout << minans;
  return 0;
}
