#include <bits/stdc++.h>
using namespace std;
int a[15], b[15];
char s[205];
int main() {
  int t;
  cin >> t >> s;
  while (t) {
    a[t % 10]++;
    t /= 10;
  }
  int len = strlen(s);
  for (int i = 0; i < len; ++i) ++b[s[i] - '0'];
  a[2] += a[5];
  a[5] = 0;
  b[2] += b[5];
  a[6] += a[9];
  a[9] = 0;
  b[6] += b[9];
  int ans = 0x3f3f3f3f;
  for (int i = 0; i < 10; ++i)
    if (a[i]) ans = min(ans, b[i] / a[i]);
  cout << ans << endl;
  return 0;
}
