#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("sse2")
using namespace std;
bool isPowerOfTwo(long long int x) { return x && (!(x & (x - 1))); }
void solve() {
  string t, str;
  cin >> t >> str;
  long long int ans = 2e9;
  map<long long int, long long int> hash1, hash2;
  for (long long int i = 0; i < t.size(); ++i) {
    long long int x = t[i] - '0';
    if (x == 5)
      x = 2;
    else if (x == 9)
      x = 6;
    hash1[x]++;
  }
  for (long long int i = 0; i < str.size(); ++i) {
    long long int x = str[i] - '0';
    if (x == 5)
      x = 2;
    else if (x == 9)
      x = 6;
    hash2[x]++;
  }
  for (auto i : hash1) ans = min(ans, hash2[i.first] / i.second);
  cout << ans;
}
int32_t main() {
  std::ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int T = 1;
  while (T--) solve();
  return 0;
}
