#include <bits/stdc++.h>
using namespace std;
int aux[10], times[10];
int main() {
  string t;
  cin >> t;
  string arr;
  cin >> arr;
  for (int i = 0; i < arr.size(); i++) {
    aux[arr[i] - '0']++;
    if (arr[i] == '2') aux[5]++;
    if (arr[i] == '5') aux[2]++;
    if (arr[i] == '6') aux[9]++;
    if (arr[i] == '9') aux[6]++;
  }
  int mini = 2000000000;
  for (int i = 0; i < t.size(); i++) {
    times[t[i] - '0']++;
    if (t[i] == '2') times[5]++;
    if (t[i] == '5') times[2]++;
    if (t[i] == '6') times[9]++;
    if (t[i] == '9') times[6]++;
  }
  for (int i = 0; i < 10; i++) {
    if (times[i] != 0) {
      if (mini > aux[i] / times[i]) mini = aux[i] / times[i];
    }
  }
  cout << mini;
  return 0;
}
