#include
#include
#include
#include
#include
#include
#include
#include
using namespace std;
const int maxn = 1e6+100;
const int inf = 0x7fffffff;
char a[maxn];
int len,ans;
long long m;
void sloveDict(int &i);
void sloveInt(int &i);
void sloveList(int &i);
void sloveString(int &i);
void sloveInt(int &i)
{
m-=3;
if(m<0)
ans = min(i,ans);
int num = -1;
while(ans==inf && a[++i]!='e')
{
if(num!=0 && a[i]>='0' && a[i]<='9')
{
if(num==-1)
num = a[i]-'0';
else
m--;
if(m<0)
ans = min(ans,i);
}
else
ans = min(ans,i);
}
if(num==-1)
ans = min(ans,i);
}
void sloveString(int &i)
{
long long tlen = a[i]-'0';
m -= tlen+2;
if(m<0)
ans = min(ans,i);
while(ans==inf && a[++i]!=':')
{
if(tlen!=0 && a[i]>='0' && a[i]<='9')
{
m -= (tlen*10+a[i]-'0')+1 - tlen;
tlen = tlen*10+a[i]-'0';
if(m<0)
ans = min(ans,i);
}
else
ans = min(ans,i);
}
while(tlen&&i i++,tlen--;
if(i==len)
ans = min(ans,i);
}
void sloveList(int &i)
{
m -= 2;
if(m<0)
ans = min(ans,i);
while(ans==inf&&a[++i]!='e')
{
if(a[i]=='l')
sloveList(i);
else if(a[i]=='d')
sloveDict(i);
else if(a[i]=='i')
sloveInt(i);
else if(a[i]<='9' && a[i]>='0')
sloveString(i);
else
ans = min(i,ans);
}
}
void sloveDict(int &i)
{
m-=2;
if(m<0)
ans = min(i,ans);
int num = 0;
while(ans==inf && a[++i]!='e')
{
num^=1;
if(num)
m -= 2;
else
m += 2;
if(a[i]=='l')
sloveList(i);
else if(a[i]=='d')
sloveDict(i);
else if(a[i]=='i')
sloveInt(i);
else if(a[i]<='9' && a[i]>='0')
sloveString(i);
else
ans = min(i,ans);
}
if(num)
ans = min(i,ans);
}
int main()
{
freopen("input.txt","r",stdin);
freopen("output.txt","w",stdout);
scanf("%I64d %s",&m,a);
len = strlen(a);
int i = 0;
ans = inf;
if(a[0]=='l')
sloveList(i);
else if(a[0]=='d')
sloveDict(i);
else if(a[0]=='i')
sloveInt(i);
else if(a[0]<='9' && a[0]>='0')
sloveString(i);
else
ans = min(0,ans);
i++;
if(i ans = min(i,ans);
if(ans!=inf)
printf("Error at position %d!\n",ans);
else
puts("ok");
return 0;
}