#include <iostream>
#include <cmath>
#include <algorithm>
#include <vector>
#include <cstring>
using namespace std;
int main()
{
    freopen("DATA1.txt", "r", stdin);
    freopen("OUT1.txt", "w", stdout);
    for (int ii = 0; ii < 5; ii++)
    {
        int x, y, pow2[12];
        pow2[0] = 1;
        for (int i = 1; i < 11; i++)
        {
            pow2[i] = 2*pow2[i-1];
        }
        cin >> x >> y;
        string s = "";
        bool d = 0;
        if (x == 0) s = "0";
        else{
        for (int i = 10; i >= 0; --i)
        {
            if (pow2[i] <= x)
            {
                x -= pow2[i];
                s += "1";
                d++;
            }
            else if (d)
            {
                s += "0";
            }
        }
        }
        if (s.length() -  y - 1 <0 || s.length() -  y - 1 >= s.length()) cout << 0 << endl;
        else cout << s[s.length() -  y - 1] << endl;
//        cout << (((1<<y)&x)==(1<<y)) << endl;
    }
    return 0;
}

