#include <bits/stdc++.h>
using namespace std;
int a[10];
int b[10];
string s, t;
int ans = 1e9;
int main() {
  cin >> t;
  cin >> s;
  for (int i = 0; i < t.length(); i++)
    if (t[i] == '9')
      b[6]++;
    else if (t[i] == '5')
      b[2]++;
    else
      b[t[i] - '0']++;
  for (int i = 0; i < s.length(); i++)
    if (s[i] == '9')
      a[6]++;
    else if (s[i] == '5')
      a[2]++;
    else
      a[s[i] - '0']++;
  for (int i = 0; i < 10; i++)
    if (b[i]) ans = min(ans, a[i] / b[i]);
  cout << ans;
  return 0;
}
