#include #include #include using namespace std; int main() { int n, m; cin >> n >> m; vector a(n), b(m); for(auto& x: a) cin >> x; for(auto& x: b) cin >> x; int ret = 0; for(int q = 0; ret == 0 && q < 2; q++) { string curr = " "; for(auto out: a) curr += to_string(out) + " "; for(auto out: a) curr += to_string(out) + " "; string want = " "; for(auto out: b) want += to_string(out) + " "; if(curr.find(want) != string::npos) ret = 1; reverse(a.begin(), a.end()); } cout << ret << "\n"; }