#include <bits/stdc++.h>
using namespace std;
const int INF = 1e9 + 5;
bool is(char x, char y) {
  if ((x == '2' || x == '5') && (y == '2' || y == '5')) return true;
  if ((x == '6' || x == '9') && (y == '6' || y == '9')) return true;
  if (x == y) return true;
  return false;
}
void solve() {
  string s, t;
  cin >> s >> t;
  vector<bool> used(t.size(), false);
  int cnt = 0;
  while (true) {
    bool q = true;
    for (int i = 0; i < s.size(); i++) {
      bool w = false;
      for (int j = 0; j < t.size(); j++) {
        if (used[j]) continue;
        if (is(s[i], t[j])) {
          used[j] = true;
          w = true;
          break;
        }
      }
      if (!w) {
        q = false;
        break;
      }
    }
    if (!q) break;
    cnt++;
  }
  cout << cnt;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ;
  int t = 1;
  while (t--) solve();
}
