#include <bits/stdc++.h>
const long long INF = 1e18;
const int32_t M = 1e9 + 7;
using namespace std;
void solve() {
  long long n;
  cin >> n;
  string s;
  cin >> s;
  long long nc[10], second[10], n2 = 0, n6 = 0, s2 = 0, s6 = 0;
  memset(nc, 0, sizeof(nc)), memset(second, 0, sizeof(second));
  while (n != 0) {
    long long t = n % 10;
    if (t == 5 || t == 2)
      n2++;
    else if (t == 6 || t == 9)
      n6++;
    else
      nc[t]++;
    n /= 10;
  }
  for (auto it : s) {
    long long t = it - '0';
    if (t == 5 || t == 2)
      s2++;
    else if (t == 6 || t == 9)
      s6++;
    else
      second[t]++;
  }
  long long mn = INF;
  for (long long i = 0; i < 10; i++) {
    if (i != 2 && i != 5 && i != 6 && i != 9 && nc[i] != 0) {
      long long t = second[i] / nc[i];
      mn = min(t, mn);
    }
  }
  long long a2 = INF, a6 = INF;
  if (n2 > 0) a2 = s2 / n2;
  if (n6 > 0) a6 = s6 / n6;
  mn = min(mn, a2);
  mn = min(mn, a6);
  cout << mn;
}
int32_t main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  long long t = 1;
  while (t--) solve();
  return 0;
}
