#include <iostream>
#include <cmath>
using namespace std;
int x[2001][2001];
int main() {
int n;
cin >> n;
int pos;
bool f = true;
int x1 = 1001, y1 = 1001;
for(int i = 0; i< n && f; i++) {
cin >> pos;
if(x[x1][y1] == 1) {
cout << i;
f = false;
}
else x[x1][y1] = 1;
switch (pos) {
case 1: x1--; y1++; break;
case 3: x1++;
case 2: y1++; break;
case 4: x1++; break;
case 5: x1++;
case 6: y1--; break;
case 7: y1--;
case 8: x1--;
}
}
if (f) cout << "Ok" << endl << abs(x1-1001) + abs(y1-1001);
return 0;
}
I2luY2x1ZGUgPGlvc3RyZWFtPgojaW5jbHVkZSA8Y21hdGg+CnVzaW5nIG5hbWVzcGFjZSBzdGQ7CiAKaW50IHhbMjAwMV1bMjAwMV07CiAKaW50IG1haW4oKSB7CiAgICBpbnQgbjsKICAgIGNpbiA+PiBuOwogICAgaW50IHBvczsKICAgIGJvb2wgZiA9IHRydWU7CiAgICBpbnQgeDEgPSAxMDAxLCB5MSA9IDEwMDE7CiAgICBmb3IoaW50IGkgPSAwOyBpPCBuICYmIGY7IGkrKykgewogICAgICAgIGNpbiA+PiBwb3M7CiAgICAgICAgaWYoeFt4MV1beTFdID09IDEpIHsgCiAgICAgICAgICAgIGNvdXQgPDwgaTsKICAgICAgICAgICAgZiA9IGZhbHNlOwogICAgICAgIH0KICAgICAgICBlbHNlIHhbeDFdW3kxXSA9IDE7CiAgICAgICAgIHN3aXRjaCAocG9zKSB7CiAgICAgICAgICAgIGNhc2UgMTogeDEtLTsgeTErKzsgYnJlYWs7CiAgICAgICAgICAgIGNhc2UgMzogeDErKzsKICAgICAgICAgICAgY2FzZSAyOiB5MSsrOyBicmVhazsKICAgICAgICAgICAgY2FzZSA0OiB4MSsrOyBicmVhazsKICAgICAgICAgICAgY2FzZSA1OiB4MSsrOwogICAgICAgICAgICBjYXNlIDY6IHkxLS07IGJyZWFrOwogICAgICAgICAgICBjYXNlIDc6IHkxLS07IAogICAgICAgICAgICBjYXNlIDg6IHgxLS07CiAgICAgICAgfQogICAgfQogICAgaWYgKGYpIGNvdXQgPDwgIk9rIiA8PCBlbmRsIDw8IGFicyh4MS0xMDAxKSArIGFicyh5MS0xMDAxKTsKICAgIHJldHVybiAwOwp9