#include <bits/stdc++.h>
using namespace std;
bool isTestcase = false;
void fun() {
  string target, given;
  cin >> target;
  cin >> given;
  unordered_map<char, long long int> counts;
  for (long long int i = 0; i < given.size(); i++) {
    if (given[i] == '5') {
      counts['2']++;
    } else if (given[i] == '9') {
      counts['6']++;
    } else {
      counts[given[i]]++;
    }
  }
  unordered_map<char, long long int> req;
  for (long long int i = 0; i < target.size(); i++) {
    if (target[i] == '5') target[i] = '2';
    if (target[i] == '9') target[i] = '6';
    req[target[i]]++;
  }
  long long int ans = INT_MAX;
  for (auto i : req) {
    ans = min(ans, counts[i.first] / i.second);
  }
  cout << ans << endl;
}
int main(int argc, char const *argv[]) {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  if (isTestcase) {
    int t;
    cin >> t;
    for (int n = 0; n < t; n++) {
      fun();
    }
  } else {
    fun();
  }
  return 0;
}
