#include<iostream>
using namespace std;
int changeToInt(char number)
{
if(number == '0')
return 0;
if(number == '1')
return 1;
if(number == '2')
return 2;
if(number == '3')
return 3;
if(number == '4')
return 4;
if(number == '5')
return 5;
if(number == '6')
return 6;
if(number == '7')
return 7;
if(number == '8')
return 8;
if(number == '9')
return 9;
}
int main()
{
ios_base::sync_with_stdio(0);
int licznik=0;
int n;
char pom;
cin>>n;
char liczba[n];
int result[n];
int numbersInt[n];
for(int i=0;i<n;i++)
{
cin>>pom;
result[i]=0;
numbersInt[i]=changeToInt(pom);
}
if(numbersInt[n-1]!=5 && numbersInt[n-1]!=6)
{
cout<<'1'<<endl;
}
else
{
int indexResult=1;
int resultMul, cyfraJednosci, przeniesienie, przeniesienieAdd;
for(int i=n-1;i>=0;i--)
{
przeniesienie=0;
przeniesienieAdd=0;
if(numbersInt[i]==0)
{
}
else
{
for(int j=n-1;j>=licznik;j--)
{
resultMul=numbersInt[i]*numbersInt[j]+przeniesienie;
cyfraJednosci=resultMul%10;
if(resultMul>9)
przeniesienie=resultMul/10;
else
przeniesienie=0;
result[j-licznik]+=cyfraJednosci+przeniesienieAdd;
if(result[j-licznik]>9)
{
przeniesienieAdd=result[j-licznik]/10;
result[j-licznik]=result[j-licznik]%10;
}
else
{
przeniesienieAdd=0;
}
if(result[i]!=numbersInt[i])
{
cout<<indexResult<<endl;
return 0;
}
}
}
indexResult++;
licznik++;
}
cout<<"OK"<<endl;
}
return 0;
}
I2luY2x1ZGU8aW9zdHJlYW0+Cgp1c2luZyBuYW1lc3BhY2Ugc3RkOwppbnQgY2hhbmdlVG9JbnQoY2hhciBudW1iZXIpCnsKICAgIGlmKG51bWJlciA9PSAnMCcpCiAgICAgICAgcmV0dXJuIDA7CiAgICBpZihudW1iZXIgPT0gJzEnKQogICAgICAgIHJldHVybiAxOwogICAgaWYobnVtYmVyID09ICcyJykKICAgICAgICByZXR1cm4gMjsKICAgIGlmKG51bWJlciA9PSAnMycpCiAgICAgICAgcmV0dXJuIDM7CiAgICBpZihudW1iZXIgPT0gJzQnKQogICAgICAgIHJldHVybiA0OwogICAgaWYobnVtYmVyID09ICc1JykKICAgICAgICByZXR1cm4gNTsKICAgIGlmKG51bWJlciA9PSAnNicpCiAgICAgICAgcmV0dXJuIDY7CiAgICBpZihudW1iZXIgPT0gJzcnKQogICAgICAgIHJldHVybiA3OwogICAgaWYobnVtYmVyID09ICc4JykKICAgICAgICByZXR1cm4gODsKICAgIGlmKG51bWJlciA9PSAnOScpCiAgICAgICAgcmV0dXJuIDk7Cn0KCmludCBtYWluKCkKewogICAgaW9zX2Jhc2U6OnN5bmNfd2l0aF9zdGRpbygwKTsKICAgIGludCBsaWN6bmlrPTA7CiAgICBpbnQgbjsKICAgIGNoYXIgcG9tOwogICAgY2luPj5uOwogICAgY2hhciBsaWN6YmFbbl07CiAgICBpbnQgcmVzdWx0W25dOwogICAgaW50IG51bWJlcnNJbnRbbl07CiAgICBmb3IoaW50IGk9MDtpPG47aSsrKQogICAgewogICAgICAgIGNpbj4+cG9tOwogICAgICAgIHJlc3VsdFtpXT0wOwogICAgICAgIG51bWJlcnNJbnRbaV09Y2hhbmdlVG9JbnQocG9tKTsKCiAgICB9CiAgICBpZihudW1iZXJzSW50W24tMV0hPTUgJiYgbnVtYmVyc0ludFtuLTFdIT02KQogICAgewogICAgICAgIGNvdXQ8PCcxJzw8ZW5kbDsKICAgIH0KICAgIGVsc2UKICAgIHsKICAgICAgICBpbnQgaW5kZXhSZXN1bHQ9MTsKICAgICAgICBpbnQgcmVzdWx0TXVsLCBjeWZyYUplZG5vc2NpLCBwcnplbmllc2llbmllLCBwcnplbmllc2llbmllQWRkOwogICAgICAgIGZvcihpbnQgaT1uLTE7aT49MDtpLS0pCiAgICAgICAgewogICAgICAgICAgICBwcnplbmllc2llbmllPTA7CiAgICAgICAgICAgIHByemVuaWVzaWVuaWVBZGQ9MDsKICAgICAgICAgICAgaWYobnVtYmVyc0ludFtpXT09MCkKICAgICAgICAgICAgewoKICAgICAgICAgICAgfQogICAgICAgICAgICBlbHNlCiAgICAgICAgICAgIHsKICAgICAgICAgICAgICAgIGZvcihpbnQgaj1uLTE7aj49bGljem5paztqLS0pCiAgICAgICAgICAgICAgICB7CiAgICAgICAgICAgICAgICAgICAgcmVzdWx0TXVsPW51bWJlcnNJbnRbaV0qbnVtYmVyc0ludFtqXStwcnplbmllc2llbmllOwogICAgICAgICAgICAgICAgICAgIGN5ZnJhSmVkbm9zY2k9cmVzdWx0TXVsJTEwOwoKICAgICAgICAgICAgICAgICAgICBpZihyZXN1bHRNdWw+OSkKICAgICAgICAgICAgICAgICAgICAgICAgcHJ6ZW5pZXNpZW5pZT1yZXN1bHRNdWwvMTA7CiAgICAgICAgICAgICAgICAgICAgZWxzZQogICAgICAgICAgICAgICAgICAgICAgICBwcnplbmllc2llbmllPTA7CgogICAgICAgICAgICAgICAgICAgIHJlc3VsdFtqLWxpY3puaWtdKz1jeWZyYUplZG5vc2NpK3ByemVuaWVzaWVuaWVBZGQ7CiAgICAgICAgICAgICAgICAgICAgaWYocmVzdWx0W2otbGljem5pa10+OSkKICAgICAgICAgICAgICAgICAgICB7CiAgICAgICAgICAgICAgICAgICAgICAgIHByemVuaWVzaWVuaWVBZGQ9cmVzdWx0W2otbGljem5pa10vMTA7CiAgICAgICAgICAgICAgICAgICAgICAgIHJlc3VsdFtqLWxpY3puaWtdPXJlc3VsdFtqLWxpY3puaWtdJTEwOwoKICAgICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgICAgZWxzZQogICAgICAgICAgICAgICAgICAgIHsKICAgICAgICAgICAgICAgICAgICAgICAgcHJ6ZW5pZXNpZW5pZUFkZD0wOwogICAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgICBpZihyZXN1bHRbaV0hPW51bWJlcnNJbnRbaV0pCiAgICAgICAgICAgICAgICAgICAgewogICAgICAgICAgICAgICAgICAgICAgICBjb3V0PDxpbmRleFJlc3VsdDw8ZW5kbDsKICAgICAgICAgICAgICAgICAgICAgICAgcmV0dXJuIDA7CiAgICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgfQogICAgICAgICAgICB9CiAgICAgICAgICAgIGluZGV4UmVzdWx0Kys7CiAgICAgICAgICAgIGxpY3puaWsrKzsKCiAgICAgICAgfQoKICAgICAgICAgICAgY291dDw8Ik9LIjw8ZW5kbDsKICAgIH0KICAgIHJldHVybiAwOwp9Cg==