#include <bits/stdc++.h>
using namespace std;
int Set(int N, int pos) { return N = N | (1 << pos); }
int reset(int N, int pos) { return N = N & ~(1 << pos); }
bool check(int N, int pos) { return (bool)(N & (1 << pos)); }
int thas[30], shas[30];
int main() {
  string t, s;
  cin >> t >> s;
  for (int i = 0; i < t.size(); i++) {
    if (t[i] == '9') t[i] = '6';
    if (t[i] == '5') t[i] = '2';
    thas[t[i] - '0']++;
  }
  for (int i = 0; i < s.size(); i++) {
    if (s[i] == '9') s[i] = '6';
    if (s[i] == '5') s[i] = '2';
    shas[s[i] - '0']++;
  }
  int mn = INT_MAX;
  for (int i = 0; i <= 9; i++) {
    if (thas[i] == 0) continue;
    if (thas[i] > shas[i]) {
      mn = 0;
      break;
    }
    mn = min(mn, shas[i] / thas[i]);
  }
  cout << mn;
  return 0;
}
