#include <bits/stdc++.h>
using namespace std;
inline bool check(int x[], int y[]) {
  for (int i = 0; i < 10; i++) {
    if (y[i] < x[i]) {
      int diff = x[i] - y[i];
      y[i] = 0;
      if (i == 2 && y[5] >= diff) {
        y[5] -= diff;
      } else if (i == 5 && y[2] >= diff) {
        y[2] -= diff;
      } else if (i == 6 && y[9] >= diff) {
        y[9] -= diff;
      } else if (i == 9 && y[6] >= diff) {
        y[6] -= diff;
      } else {
        return false;
      }
    } else {
      y[i] -= x[i];
    }
  }
  return true;
}
int main() {
  string t, str;
  cin >> t >> str;
  int tarr[] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
  int strarr[] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
  for (int i = 0; i < t.length(); i++) tarr[t[i] - '0']++;
  for (int i = 0; i < str.length(); i++) strarr[str[i] - '0']++;
  int ans = 0;
  while (check(tarr, strarr)) ans++;
  cout << ans;
  return 0;
}
