#include <bits/stdc++.h>
using namespace std;
const int N = 100010;
int n;
int a[11], b[11];
char s[1111];
int main() {
  scanf("%d", &n);
  scanf("%s", s);
  while (n) b[n % 10]++, n /= 10;
  for (int i = 0; s[i]; i++) a[s[i] - '0']++;
  a[2] += a[5];
  b[2] += b[5];
  a[6] += a[9];
  b[6] += b[9];
  a[5] = a[9] = b[5] = b[9] = 0;
  int ret = 1111;
  for (int i = 0; i < 10; i++)
    if (b[i]) ret = min(ret, a[i] / b[i]);
  cout << ret << endl;
  return 0;
}
