#include <iostream>
#include <vector>

using namespace std;

int main()
{
    int n, x, f=1;
    vector<int> b;
    int a;
    int count = 0;
    while (cin >> n>>x)
    {    
        f = n;
        for (;n>0;)
        {
            a = f % 10;
            b.push_back(a);
            f = f / 10;
            if (f == 0)
            {
                n--;
                f = n;
                continue;
            }
        }
        for (unsigned int i = 0; i < b.size(); i++)
        {
            if (x == b.at(i))
            {
                count++;
            }
        }
        cout << count << endl;
    }
}