#include <iostream>
#include <cmath>
using namespace std;
int x[2001][2001];
int main() {
int n;
cin>>n;
int move;
int xPos=1001, yPos=1001;
for(int i=0; i<n; i++) {
cin>>move;
if(x[xPos][yPos]==1) {
cout<<i;
return 0;
}
else x[xPos][yPos]=1;
if(move==1) {
xPos--;
yPos++;
}
if(move==2) {
yPos++;
}
if(move==3) {
xPos++;
yPos++;
}
if(move==4) {
xPos++;
}
if(move==5) {
xPos++;
yPos--;
}
if(move==6) {
yPos--;
}
if(move==7) {
xPos--;
yPos--;
}
if(move==8) {
xPos--;
}
}
cout<<"Ok"<<endl<<abs(xPos-1001)+abs(yPos-1001);
return 0;
}
I2luY2x1ZGUgPGlvc3RyZWFtPgojaW5jbHVkZSA8Y21hdGg+CnVzaW5nIG5hbWVzcGFjZSBzdGQ7CgppbnQgeFsyMDAxXVsyMDAxXTsKCmludCBtYWluKCkgewoJaW50IG47CgljaW4+Pm47CglpbnQgbW92ZTsKCWludCB4UG9zPTEwMDEsIHlQb3M9MTAwMTsKCWZvcihpbnQgaT0wOyBpPG47IGkrKykgewoJCWNpbj4+bW92ZTsKCQlpZih4W3hQb3NdW3lQb3NdPT0xKSB7IAoJCQljb3V0PDxpOwoJCQlyZXR1cm4gMDsKCQl9CgkJZWxzZSB4W3hQb3NdW3lQb3NdPTE7CgkJaWYobW92ZT09MSkgewoJCQl4UG9zLS07CgkJCXlQb3MrKzsKCQl9CgkJaWYobW92ZT09MikgewoJCQl5UG9zKys7CgkJfQoJCWlmKG1vdmU9PTMpIHsKCQkJeFBvcysrOwoJCQl5UG9zKys7CgkJfQoJCWlmKG1vdmU9PTQpIHsKCQkJeFBvcysrOwoJCX0KCQlpZihtb3ZlPT01KSB7CgkJCXhQb3MrKzsKCQkJeVBvcy0tOwoJCX0KCQlpZihtb3ZlPT02KSB7CgkJCXlQb3MtLTsKCQl9CgkJaWYobW92ZT09NykgewoJCQl4UG9zLS07CgkJCXlQb3MtLTsKCQl9CgkJaWYobW92ZT09OCkgewoJCQl4UG9zLS07CgkJfQoJfQoJY291dDw8Ik9rIjw8ZW5kbDw8YWJzKHhQb3MtMTAwMSkrYWJzKHlQb3MtMTAwMSk7CglyZXR1cm4gMDsKfQ==