#include <bits/stdc++.h>
using namespace std;
const int maxn = 10 + 5;
const int INF = 1000000000;
int num[maxn];
int cost[maxn];
string s;
int main() {
  int t;
  while (cin >> t >> s) {
    int ans = 0;
    memset(num, 0, sizeof(num));
    for (int i = 0; i < s.length(); i++) {
      if (s[i] == '6' || s[i] == '9')
        num[6]++;
      else if (s[i] == '2' || s[i] == '5')
        num[2]++;
      else
        num[s[i] - '0']++;
    }
    memset(cost, 0, sizeof(cost));
    while (t) {
      int tem = t % 10;
      if (tem == 9)
        cost[6]++;
      else if (tem == 5)
        cost[2]++;
      else
        cost[tem]++;
      t = t / 10;
    }
    ans = INF;
    for (int i = 0; i <= 9; i++) {
      if (cost[i]) ans = min(ans, num[i] / cost[i]);
    }
    cout << ans << endl;
  }
  return 0;
}
