#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:256000000")
using namespace std;
int ans, t, i, n, sum, h;
int cnt[20], need[20];
char s[300];
int main() {
  scanf("%d", &t);
  for (; t; t /= 10) {
    ++need[t % 10];
  }
  scanf("%s", s + 1);
  n = strlen(s + 1);
  for (i = 1; i <= n; ++i) {
    ++cnt[s[i] - 48];
  }
  while (cnt[0] >= need[0] && cnt[1] >= need[1] &&
         cnt[2] + cnt[5] >= need[2] + need[5] && cnt[3] >= need[3] &&
         cnt[4] >= need[4] && cnt[6] + cnt[9] >= need[6] + need[9] &&
         cnt[7] >= need[7] && cnt[8] >= need[8]) {
    ++ans;
    cnt[1] -= need[1];
    cnt[3] -= need[3];
    cnt[4] -= need[4];
    cnt[7] -= need[7];
    cnt[8] -= need[8];
    sum = need[2] + need[5];
    h = min(sum, cnt[2]);
    cnt[2] -= h;
    sum -= h;
    h = min(sum, cnt[5]);
    cnt[5] -= h;
    sum -= h;
    sum = need[6] + need[9];
    h = min(sum, cnt[6]);
    cnt[6] -= h;
    sum -= h;
    h = min(sum, cnt[9]);
    cnt[9] -= h;
    sum -= h;
    cnt[0] -= need[0];
  }
  cout << ans << "\n";
  return 0;
}
