#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
using namespace std;
int main() {
long long a, b;
cin >> a >> b;
long long ans = 2;
for (int i = 1; i <= a; i++) {
ans = (ans * ans) % b;
}
cout << ans << endl;
return 0;
}
I2luY2x1ZGUgPGNtYXRoPgojaW5jbHVkZSA8Y3N0ZGlvPgojaW5jbHVkZSA8dmVjdG9yPgojaW5jbHVkZSA8aW9zdHJlYW0+CiNpbmNsdWRlIDxhbGdvcml0aG0+CnVzaW5nIG5hbWVzcGFjZSBzdGQ7CgoKaW50IG1haW4oKSB7CiAgICBsb25nIGxvbmcgYSwgYjsKICAgIGNpbiA+PiBhID4+IGI7CiAgICBsb25nIGxvbmcgYW5zID0gMjsKICAgIGZvciAoaW50IGkgPSAxOyBpIDw9IGE7IGkrKykgewogICAgICAgIGFucyA9IChhbnMgKiBhbnMpICUgYjsKICAgIH0KICAgIGNvdXQgPDwgYW5zIDw8IGVuZGw7CiAgICByZXR1cm4gMDsKfQo=