#include <iostream>
using namespace std;

int main() 
{
    string a;
    cin>>a;
    int i=0;
    int len=a.size();
    int count=0;
    for(i=0;i<len;i++)
    {
        if(a[i]!=',')
        {
            string b;
            while(i<len  &&  a[i]!=',')
            {
                b+=a[i];
                i++;
            }
            i--;
            int j=0;
            int len2=b.size();
            int c=0;
            for(j=0;j<len2;j++)
            {
                c*=10;
                c+=b[j]-'0';
            }
            if(count!=c)
            {
                cout<<count;
                return 0;
            }
            count++;
        }
    }
    cout<<count;
    return 0;
}