#include <bits/stdc++.h>
using namespace std;
int d[10], p[10];
int main() {
  int t;
  cin >> t;
  int i = t;
  int k = 0;
  while (i > 0) {
    int temp = i % 10;
    if (temp == 5) temp = 2;
    if (temp == 9) temp = 6;
    d[temp]++;
    i /= 10;
    k++;
  }
  string s;
  cin >> s;
  for (int j = 0; j < s.size(); j++) {
    if (s[j] == '5')
      p[2]++;
    else if (s[j] == '9')
      p[6]++;
    else
      p[(int)s[j] - 48]++;
  }
  int ans = s.size() / k;
  for (int i = 0; i < 10; i++) {
    if (d[i] != 0) {
      ans = min(ans, p[i] / d[i]);
    }
  }
  cout << ans << endl;
  return 0;
}
