#include <bits/stdc++.h>
using namespace std;
string x, s;         
long long sumx[10], sums[10]; 
long long ans = 1e18;
int main() {
    freopen("pocket.in", "r", stdin);
    freopen("pocket.out", "w", stdout);
    cin >> x >> s; 
    for (int i = 0; i < x.size(); i++) {
        int c = x[i] - '0';
        if (c == 5)
            c = 2;
        if (c == 9)
            c = 6;
        sumx[c]++; 
    }
    for (int i = 0; i < s.size(); i++) {
        int c = s[i] - '0';
        if (c == 5)
            c = 2;
        if (c == 9)
            c = 6;
        sums[c]++; 
    }
    for (int i = 0; i <= 9; i++) { 
        if (sumx[i]) {
            ans = min(ans, sums[i] / sumx[i]);
        }
    }
    cout << ans << endl;
    return 0;
}