#include <bits/stdc++.h>
using namespace std;
long long raised(long long x, long long y) {
  long long res = 1;
  while (y > 0) {
    if (y & 1) {
      res = res * x;
    }
    y = y >> 1;
    x = x * x;
  }
  return res;
}
long long raisedmod(long long x, long long y, long long p) {
  int res = 1;
  x = x % p;
  while (y > 0) {
    if (y & 1) {
      res = (res * x) % p;
    }
    y = y >> 1;
    x = (x * x) % p;
  }
  return res;
}
long long gcd(long long a, long long b) {
  if (b == 0) return a;
  return gcd(b, a % b);
}
long long fact(long long n) {
  long long res = 1;
  for (long long i = 2; i <= n; i++) res = res * i;
  return res;
}
long long nCr(long long n, long long r) {
  return fact(n) / (fact(r) * fact(n - r));
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  ;
  long long t;
  t = 1;
  while (t--) {
    string t, s;
    cin >> t >> s;
    map<char, long long> mp;
    mp['0'] = 0;
    mp['1'] = 0;
    mp['2'] = 0;
    mp['3'] = 0;
    mp['4'] = 0;
    mp['5'] = 0;
    mp['6'] = 0;
    mp['7'] = 0;
    mp['8'] = 0;
    mp['9'] = 0;
    for (long long i = 0; i < s.size(); i++) {
      mp[s[i]]++;
    }
    mp['6'] += mp['9'];
    mp['9'] = mp['6'];
    mp['5'] += mp['2'];
    mp['2'] = mp['5'];
    map<char, long long> mp1;
    vector<long long> v;
    for (long long i = 0; i < t.size(); i++) {
      mp1[t[i]]++;
    }
    mp1['6'] += mp1['9'];
    mp1['9'] = mp1['6'];
    mp1['5'] += mp1['2'];
    mp1['2'] = mp1['5'];
    for (auto &it : mp1) {
      if (it.second != 0) v.push_back(mp[it.first] / it.second);
    }
    cout << *min_element(v.begin(), v.end()) << endl;
  }
  return 0;
}
