#include <bits/stdc++.h>

using namespace std;

int main()
{
    long int n;
    cin>>n;
    long int a[n];
    char b[n];
    for(int i=0;i<n;i++)
    {
        cin>>b[i]>>a[i];
    }
    int v=0,r=0;
    for(int i=0;i<n;i++)
    {
        if(b[i]=='-')
            v++;
        else
            v=0;
        if(v>r)
            r=v;
    }
    cout<<r;
    return 0;
}


#include <bits/stdc++.h>

using namespace std;
int main()
{
    int n;
    cin>>n;
    long int a[n],v=0,r=0;
    char b[n];
    for(int i=0;i<n;i++)
        cin>>b[i]>>a[i];
    for(int i=0;i<n;i++)
    {
        if((b[i]=='+')&&(r+1>1))
            v++;
        else if(b[i]=='-')
        {
            v++;
            r--;
        }
        else if(b[i]=='+')
            r++;
    }
    cout<<v;
    return 0;
}


#include <bits/stdc++.h>

using namespace std;
int main()
{
    long int n;
    cin>>n;
    long int a[n],v=0,r=0;
    char b[n];
    for(int i=0;i<n;i++)
        cin>>b[i]>>a[i];
    for(int i=0;i<n;i++)
    {
        v++;
        if(b[i]=='+')
            r++;
        else if(b[i]=='-'&&i>0)
        {
            for(int j=i-1;j>=0;j--)
            {
                if(a[i]==a[j])
                {
                    v--;
                    r--;
                    break;
                }
            }
        }
    }
    cout<<v-r;
    return 0;
}


#include <bits/stdc++.h>

using namespace std;
int main()
{
    int n;
    cin>>n;
    long int a[n],v=0,r=0;
    char b[n];
    for(int i=0;i<n;i++)
        cin>>b[i]>>a[i];
    for(int i=0;i<n;i++)
    {
        if((b[i]=='+')&&(r+1>0))
            v++;
        else if(b[i]=='-')
        {
            v++;
            r--;
        }
        else if(b[i]=='+')
            r++;
    }
    cout<<v;
    return 0;
}


#include <bits/stdc++.h>

using namespace std;
int main()
{
    long int n;
    cin>>n;
    long int a[n],v=0,r=0,f=0,c[n],s=1;
    char b[n];
    for(int i=0;i<n;i++)
        cin>>b[i]>>a[i];
    for(int i=0;i<n;i++)
    {
        if(b[i]=='+')
        {
            v++;
            c[f]=a[i];
            f++;
        }
        else if(b[i]=='-')
        {
            for(int j=0;j<f;j++)
            {
                if(a[i]==c[j])
                {
                    v--;
                    r++;
                    break;
                }
                if(j==f-1)
                {
                    v++;
                    s=0;
                }
            }
            if(s)
                v++;
        }
        s=1;
    }
    cout<<v-r;
    return 0;
}


#include <bits/stdc++.h>

using namespace std;
int main()
{
    int n;
    cin>>n;
    long int a[n],v=0,r=0;
    char b[n];
    for(int i=0;i<n;i++)
        cin>>b[i]>>a[i];
    for(int i=0;i<n;i++)
    {
        if(b[i]=='+'&&r+1>0)
        {
            v++;
            r++;
        }
        else if(b[i]=='-')
        {
            v++;
            r--;
        }
        else if(b[i]=='+')
            r++;
    }
    cout<<v;
    return 0;
}


#include <bits/stdc++.h>

using namespace std;
int main()
{
    long int n;
    cin>>n;
    long int a[n],v=0,r=0,f=0,c[n];
    char b[n];
    for(int i=0;i<n;i++)
        cin>>b[i]>>a[i];
    for(int i=0;i<n;i++)
    {
        if(b[i]=='+')
        {
            v++;
            c[f]=a[i];
            f++;
        }
        else if(b[i]=='-')
        {
            for(int j=0;j<f;j++)
            {
                if(a[i]==c[j])
                {
                    v--;
                    break;
                }
                if(j==f-1)
                    v++;
            }
        }
    }
    cout<<v;
    return 0;
}


#include <iostream>
#include <stdio.h>

#define ENTERED 0
#define LEFT    1
using namespace std;

int main()
{
    int n;
    scanf("%d", &n);

    int ans = 0, tmp = 0, cnt = 0;
    int state;

    char symbol;
    while (n--)
    {
        scanf("%c %d", &symbol, &tmp);
        if (symbol == '+' && state != ENTERED)
        {
            state = ENTERED;
            ans = max(ans, cnt);
            cnt = 1;
        }
        else if (symbol == '-' && state != LEFT)
        {
            state = LEFT;
            ans = max(ans, cnt);
            cnt = 1;
        }
        else
            cnt++;
    }
}


#include <iostream>
#include <stdio.h>

#define ENTERED 0
#define LEFT    1
using namespace std;

int main()
{
    int n;
    scanf("%d", &n);

    int ans = 0, tmp = 0, cnt = 1;
    int state = ENTERED;

    char symbol;
    while (n--)
    {
        cin >> symbol >> tmp;
        if (symbol == '+' && state != ENTERED)
        {
            state = ENTERED;
            ans = max(ans, cnt);
            cnt = 1;
        }
        else if (symbol == '-' && state != LEFT)
        {
            state = LEFT;
            ans = max(ans, cnt);
            cnt = 1;
        }
        else
            cnt++;
    }
    printf("%d", ans);
}


#include <iostream>
#include <stdio.h>

#define ENTERED 0
#define LEFT    1
using namespace std;

int main()
{
    int n;
    scanf("%d", &n);

    int ans = 0, tmp = 0, cnt = 1;
    int state = ENTERED;

    char symbol;
    while (n--)
    {
        cin >> symbol >> tmp;
        if (symbol == '+' && state != ENTERED)
        {
            state = ENTERED;
            ans = max(ans, cnt);
            cnt = 1;
        }
        else if (symbol == '-' && state != LEFT)
        {
            state = LEFT;
            ans = max(ans, cnt);
            cnt = 1;
        }
        else
            cnt++;
    }
    ans = max(ans, cnt);
    printf("%d", ans);
}


#include <iostream>
#include <stdio.h>

#define ENTERED 0
#define LEFT    1
using namespace std;

int main()
{
    int n;
    scanf("%d", &n);

    int ans = 0, tmp = 0, cnt = 0;
    int state;

    char symbol;
    while (n--)
    {
        scanf("%c %d", &symbol, &tmp);
        if (symbol == '+' && state != ENTERED)
        {
            state = ENTERED;
            ans = max(ans, cnt);
            cnt = 1;
        }
        else if (symbol == '-' && state != LEFT)
        {
            state = LEFT;
            ans = max(ans, cnt);
            cnt = 1;
        }
        else
            cnt++;
    }
    printf("%d", ans);
}


#include <iostream>
#include <stdio.h>

#define ENTERED 0
#define LEFT    1
using namespace std;

int main()
{
    int n;
    scanf("%d", &n);

    int ans = 0, tmp = 0, cnt = 1;
    int state = -1;

    char symbol;
    while (n--)
    {
        cin >> symbol >> tmp;
        if (symbol == '+' && state != ENTERED)
        {
            state = ENTERED;
            ans = max(ans, cnt);
            cnt = 1;
        }
        else if (symbol == '-' && state != LEFT)
        {
            state = LEFT;
            ans = max(ans, cnt);
            cnt = 1;
        }
        else
            cnt++;
    }
    ans = max(ans, cnt);
    printf("%d", ans);
}


#include <iostream>
#include <stdio.h>
#include <map>

using namespace std;

int main()
{
    int n;
    scanf("%d", &n);

    int capacity = 0;
    int known_guest = 0;

    char symbol;
    int id;
    map<int, int> member;

    while (n--)
    {
        cin >> symbol >> id;
        if (symbol == '-')
        {
            if (member.find(id) == member.end())
                capacity ++;
            else
                known_guest --;
        }
        else
        {
            member[id] = 1;
            known_guest ++;
            if (known_guest > capacity)
                capacity = known_guest;
        }
    }
    printf("%d", capacity);
}


#include<iostream>
#include<cstdio>
#include<cstring>
#include<map>
#include<cmath>
#include<algorithm>
#include<set>
using namespace std;
typedef long long ll;

set<int> cap;
int main()
{
    int n;
    while(scanf("%d",&n)!=EOF)
    {
        cap.clear();
        char op;
        int  id;
        int ans=0;
        int cur=0,cc=0;
        int ii=0,oo=0,tt=0;
        for(int i=0;i<n;i++)
        {
            cin>>op>>id;
            if(op=='-')
            {
                ii=0;
                oo++;
                if(cap.find(id)!=cap.end())
                {
                    cap.erase(id);
                    cur--;
                }
                else
                {
                    tt++;
                    cc++;
                }
            }
            else
            {
                cc-=tt;
                tt=0;
                cc++;
                oo=0;
                ii++;
                cur++;
                cap.insert(id);
            }
            ans=max(max(ans,cur),max(oo,ii));
            ans=max(ans,cc);
        }
        printf("%d\n",ans);
    }
    return 0;
}


/* 2015/7/23 */
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<set>
#include<algorithm>
#define INF 1<<29
#define mod 1000000007
//#pragma comment(linker, "/STACK:102400000,102400000")
using namespace std;

typedef long long ll;
typedef unsigned long long ull;

const int N=100007;
set<int> in,out;

int main()
{
    int n;
    while(scanf("%d",&n)==1)
    {
        in.clear();
        out.clear();
        char op[10];
        int id,ans=0;
        for(int i=0;i<n;i++)
        {
            scanf("%s%d",op,&id);
            if(op[0]=='-')
            {
                in.insert(id);
                out.insert(id);
            }
            else
            {
                for(set<int>::iterator it=out.begin();it!=out.end();it++)
                    //if(in.find(*it)!=in.end())
                        in.erase(*it);
                out.clear();
                in.insert(id);
            }
            ans=max(ans,(int)in.size());
        }
        printf("%d\n",ans);
    }
    return 0;
}


/* 2015/7/23 */
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<set>
#include<algorithm>
#define INF 1<<29
#define mod 1000000007
//#pragma comment(linker, "/STACK:102400000,102400000")
using namespace std;

typedef long long ll;
typedef unsigned long long ull;

const int N=100007;
set<int> in,out;

int main()
{
    int n;
    while(scanf("%d",&n)==1)
    {
        in.clear();
        out.clear();
        char op[10];
        int id,ans=0;
        for(int i=0;i<n;i++)
        {
            scanf("%s%d",op,&id);
            if(op[0]=='-')
            {
                in.insert(id);
                out.insert(id);
            }
            else
            {
                for(set<int>::iterator it=out.begin();it!=out.end();it++)
                        if(in.count(*it))
                            in.erase(*it);
                out.clear();
                in.insert(id);
            }
            ans=max(ans,(int)in.size());
        }
        printf("%d\n",ans);
    }
    return 0;
}


/* 2015/7/23 */
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<set>
#include<algorithm>
#define INF 1<<29
#define mod 1000000007
//#pragma comment(linker, "/STACK:102400000,102400000")
using namespace std;

typedef long long ll;
typedef unsigned long long ull;

const int N=100007;
set<int> in,out;

int main()
{
    int n;
    while(scanf("%d",&n)==1)
    {
        in.clear();
        out.clear();
        char op[10];
        int id,ans=0;
        for(int i=0;i<n;i++)
        {
            scanf("%s%d",op,&id);
            if(op[0]=='-')
            {
                in.insert(id);
                out.insert(id);
            }
            else
            {
                for(set<int>::iterator it=out.begin();it!=out.end();it++)
                    //if(in.find(*it)!=in.end())
                        in.erase(*it);
                in.insert(id);
            }
            ans=max(ans,(int)in.size());
        }
        printf("%d\n",ans);
    }
    return 0;
}


#include<iostream>
#include<cstdio>
#include<cstring>
#include<map>
#include<cmath>
#include<algorithm>
#include<set>
using namespace std;
typedef long long ll;

set<int> cap;
int main()
{
    int n;
    while(scanf("%d",&n)!=EOF)
    {
        cap.clear();
        char op;
        int  id;
        int ans=0;
        int cur=0;
        int ii=0,oo=0;
        for(int i=0;i<n;i++)
        {
            cin>>op>>id;
            if(op=='-')
            {
                ii=0;
                oo++;
                if(cap.find(id)!=cap.end())
                {
                    cap.erase(id);
                    cur--;
                }
            }
            else
            {
                oo=0;
                ii++;
                cur++;
                cap.insert(id);
            }
            ans=max(max(ans,cur),max(oo,ii));
        }
        printf("%d\n",ans);
    }
    return 0;
}


/* 2015/7/23 */
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<set>
#include<algorithm>
#define INF 1<<29
#define mod 1000000007
//#pragma comment(linker, "/STACK:102400000,102400000")
using namespace std;

typedef long long ll;
typedef unsigned long long ull;

const int N=100007;
set<int> in,out;

int main()
{
    int n;
    while(scanf("%d",&n)==1)
    {
        in.clear();
        out.clear();
        char op[10];
        int id,ans=0;
        for(int i=0;i<n;i++)
        {
            scanf("%s%d",op,&id);
            if(op[0]=='-')
            {
                in.insert(id);
                out.insert(id);
            }
            else
            {
                for(set<int>::iterator it=out.begin();it!=out.end();it++)
                        in.erase(*it);
                out.clear();
                in.insert(id);
            }
            ans=max(ans,(int)in.size());
        }
        printf("%d\n",ans);
    }
    return 0;
}


/* 2015/7/23 */
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<set>
#include<algorithm>
#define INF 1<<29
#define mod 1000000007
//#pragma comment(linker, "/STACK:102400000,102400000")
using namespace std;

typedef long long ll;
typedef unsigned long long ull;

const int N=100007;
set<int> in,out;

int main()
{
    int n;
    while(scanf("%d",&n)==1)
    {
        in.clear();
        out.clear();
        char op[10];
        int id,ans=0;
        for(int i=0;i<n;i++)
        {
            scanf("%s%d",op,&id);
            if(op[0]=='-')
            {
                if(in.count(id)) in.erase(id);
                else
                    ans++;
            }
            else
            {
                in.insert(id);
            }
            ans=max(ans,(int)in.size());
        }
        printf("%d\n",ans);
    }
    return 0;
}

/*
6
+ 12001
- 12001
- 1
- 1200
+ 1
+ 7
*/


#include<iostream>
#include<cstdio>
#include<cstring>
#include<map>
#include<cmath>
#include<algorithm>
#include<set>
using namespace std;
typedef long long ll;

set<int> cap;
int main()
{
    int n;
    while(scanf("%d",&n)==1)
    {
        cap.clear();
        char op[5];
        int  id;
        int ans=0;
        int cur=0;
        int ii=0,oo=0;
        for(int i=0;i<n;i++)
        {
            scanf("%s%d",op,id);
            if(op[0]=='-')
            {
                ii=0;
                oo++;
                if(cap.find(id)==cap.end()){
                    ;
                }
                else{
                    cap.erase(id);
                    cur--;
                }
            }
            else
            {
                oo=0;
                ii++;
                cur++;
                cap.insert(id);
            }
            ans=max(ans,cur);
            ans=max(ans,max(oo,ii));
        }
        printf("%d\n",ans);
    }
    return 0;
}


#include <bits/stdc++.h>
using namespace std;

int main(){
    #ifndef ONLINE_JUDGE
    ifstream fin("in.txt");
    #endif
    int n,vis,best=0,k;
    char c;
    cin>>n;
    set<int> rds;
    while(n--){
        cin>>c>>vis;
        if(c=='-'){
            if(rds.find(vis)==rds.end())
                rds.insert(vis);
            else
                for(auto p : rds)
                    if(p==vis){
                        rds.erase(p);
                        break;
                    }
        }
        else
            rds.insert(vis);
        k=rds.size();
        best=max(best, k);
    }
    cout<<best;
    return 0;
}


#include <bits/stdc++.h>
using namespace std;

int main(){
    #ifndef ONLINE_JUDGE
    ifstream fin("in.txt");
    #endif
    int n,vis,m=0,p=0;
    char c;
    cin>>n;
    while(n--){
        cin>>c>>vis;
        if(c=='-')
            ++m;
        else
            ++p;
    }
    m>=p?cout<<m:cout<<p;
    return 0;
}


#include <bits/stdc++.h>
#include <unordered_set>
using namespace std;

int main(){
    #ifndef ONLINE_JUDGE
    ifstream fin("in.txt");
    #endif
    int n,vis,best=0,k;
    char c;
    cin>>n;
    unordered_set<int> rds;
    while(n--){
        cin>>c>>vis;
        if(c=='-'){
            if(rds.find(vis)==rds.end())
                rds.insert(vis);
            else
                for(auto p : rds)
                    if(p==vis){
                        rds.erase(p);
                        break;
                    }
        }
        else
            rds.insert(vis);
        k=rds.size();
        best=max(best, k);
    }
    cout<<best;
    return 0;
}


#include <bits/stdc++.h>
using namespace std;

int main(){
    #ifndef ONLINE_JUDGE
    ifstream fin("in.txt");
    #endif
    int n,vis,cnt=0;
    char c;
    cin>>n;
    while(n--){
        cin>>c>>vis;
        if(c=='-')
            ++cnt;
    }
    cout<<cnt;
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define MAXN 1000100
bool ok[MAXN];

int main(){
    #ifndef ONLINE_JUDGE
    ifstream fin("in.txt");
    #endif
    int n,vis,mx=0,tx=0;
    char c;
    cin>>n;
    while(n--){
        cin>>c>>vis;
        if(c=='-'){
            if(!ok[vis])
                ++mx;
            else
                --tx;
            ok[vis]=false;
        }
        else{
            ++tx;
            mx=max(mx, tx);
            ok[vis]=true;
        }
    }
    cout<<mx;
    return 0;
}


#include <bits/stdc++.h>
using namespace std;

int main(){
    #ifndef ONLINE_JUDGE
    ifstream fin("in.txt");
    #endif
    int n,vis,best=0,k;
    char c;
    cin>>n;
    set<int> rds;
    while(n--){
        cin>>c>>vis;
        if(c=='-'){
            if(rds.find(vis)==rds.end())
                rds.insert(vis);
            else
                for(set<int>::iterator it=rds.begin();it!=rds.end();++it)
                    if(*it==vis){
                        rds.erase(it);
                        break;
                    }
        }
        else
            rds.insert(vis);
        k=rds.size();
        best=max(best, k);
    }
    cout<<best;
    return 0;
}


#include <bits/stdc++.h>
using namespace std;

int main(){
    #ifndef ONLINE_JUDGE
    ifstream fin("in.txt");
    #endif
    int n,vis,best=0,k;
    char c;
    cin>>n;
    unordered_set<int> rds;
    while(n--){
        cin>>c>>vis;
        if(c=='-'){
            if(rds.find(vis)==rds.end())
                rds.insert(vis);
            else
                for(auto p : rds)
                    if(p==vis){
                        rds.erase(p);
                        break;
                    }
        }
        else
            rds.insert(vis);
        k=rds.size();
        best=max(best, k);
    }
    cout<<best;
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define MAXN 1000100
bool ok[MAXN];

int main(){
    #ifndef ONLINE_JUDGE
    ifstream fin("in.txt");
    #endif
    int n,c,vis,mx=0,tx=0;
    cin>>n;
    while(n--){
        cin>>c>>vis;
        if(c=='-'){
            if(!ok[vis])
                ++mx;
            else
                --tx;
            ok[vis]=false;
        }
        else{
            ++tx;
            mx=max(mx, tx);
            ok[vis]=true;
        }
    }
    cout<<mx;
    return 0;
}


#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define N 3000010
using namespace std;
bool a[N];
int main()
{
    int n, i, sum = 0, b, ans = 0;
    char ch;
    scanf("%d%*c", &n);
    while(n--)
    {
        scanf("%c %d%*c", &ch, &b);
        if(ch == '+')
        {
            sum++;
            a[b] = 1;
            if(ans < sum)
                ans = sum;
        }
        else
        {
            if(!a[b])
                ans++;
            else
            {
                sum--;
                a[b] = 0;
            }
        }
    }
    printf("%d\n", ans);
    return 0;
}


#include <iostream>
#include <cstdio>
#include <set>
#include <algorithm>
using namespace std;
int main()
{
    int n,num,ans=0;
    char ch;
    scanf("%d",&n);
    set<int > s;
    s.clear();
    while(n--)
    {
        scanf(" %c %d",&ch,&num);
        if(ch=='+')
        {
            s.insert(num);
            int d=s.size();
            ans=max(ans,d);
        }
        if(ch=='-')
        {
            if(s.count(num))
                s.erase(num);
            else
                ans++;
        }
    }
    printf("%d\n",ans);
    return 0;
}


#include <iostream>
#include<stdio.h>
#include<string.h>
#include<queue>
#include<set>
#include <math.h>
#include<string.h>
#include <algorithm>
#define MAXN 2000000
using namespace std;
typedef long long LL;

int main()
{
   set<int>s;
   char ch;
   int m,i,n,j;
   int ans=0;
   scanf("%d",&n);
   for(i=1;i<=n;i++)
   {
       scanf("%*c%c %d",&ch,&m);
       if(ch=='-')
       {
           if(s.count(m))
            s.erase(m);
           else
            ans++;
       }
       else
       {
           s.insert(m);
           j=s.size();
           ans=max(j,ans);
       }
   }
   printf("%d\n",ans);
   return 0;
}


#include<stdio.h>
#include<string.h>

bool a[1000008];
int main()
{
    int n,ans;
    char ch[5];
    while(scanf("%d",&n),n>0)
    {
        memset(a,0,sizeof(a));
        int xx=0,num=0;
        while(n--)
        {
            scanf("%s%d",ch,&ans);
            if(ch[0]=='-')
            {
                if(a[ans])
                    a[ans]=0,num--;
                else
                    xx++;
            }
            else
            {
                if(num==xx)
                    xx++;

                if(a[ans]==0)
                    num++;
                a[ans]=1;

            }
        }
        printf("%d\n",xx);
    }
}


#include<stdio.h>
#include<stdlib.h>
#include<iostream>
#include <cmath>
#include<cstring>
#define LL long long
using namespace std;

char ch[110];
int num[110];
bool b[1000010];
int main(void)
{
    int n,ans,top;
    while(scanf("%d",&n)!=EOF)
    {
        top = 0;
        ans = 0;
        memset(b,0,sizeof(b));
        for(int i = 1; i <= n; i++)
        {
            getchar();
            scanf("%c %d",&ch[i],&num[i]);
            if(ch[i] == '+')
            {
                if(ans==0)
                {
                    top++;
                    b[num[i]] = 1;
                }
                else
                    ans--;
            }
            else
            {
                if(b[num[i]]==0)
                    top++;
                ans++;
            }
        }
        printf("%d\n",top);
    }
    return 0;
}


#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define N 100005
using namespace std;
bool a[N];
int main()
{
    int n, i, sum = 0, b, ans = 0;
    char ch;
    scanf("%d%*c", &n);
    while(n--)
    {
        scanf("%c %d%*c", &ch, &b);
        if(ch == '+')
        {
            sum++;
            a[b] = 1;
            if(ans < sum)
                ans = sum;
        }
        else
        {
            if(!a[b])
                ans++;
            else
            {
                sum--;
                a[b] = 0;
            }
        }
    }
    printf("%d\n", ans);
    return 0;
}


#include<iostream>
using namespace std;
int a[1000001][3];
int main(){
 //   int y;
 //freopen("test.in.cpp","r",stdin);
    int n;
    cin>>n;
    int ans=0;
    int max=0;
    for(int i=0;i<n;i++){
        char x;
        cin>>x;
        //scanf("%s",&x);
        int t;
        cin>>t;
        //scanf("%d",&t);
        if(x=='-'){
          if(a[t][1]==0){
            a[t][2]=1;
            max++;
            ans--;
            if(ans>max) max=ans;
          }
          else{
            a[t][2]=1;
            ans--;
            if(ans>max) max=ans;
          }
        }
        else{
          if(a[t][2]==1){
            a[t][1]=1;
            ans++;
            if(ans>max) max=ans;
          }
          else{
          	a[t][1]=1;
          	ans++;
          	if(ans>max) max=ans;
          }
        }
       // cout<<max<<endl;
    }
    cout<<max;
   // system("pause");
    return 0;

}


#include<iostream>
using namespace std;
int a[1000001][3];
int main(){
 //   int y;
 //freopen("test.in.cpp","r",stdin);
    int n;
    cin>>n;
    int ans=0;
    int max=0;
    for(int i=0;i<n;i++){
        char x;
        cin>>x;
        //scanf("%s",&x);
        int t;
        cin>>t;
        //scanf("%d",&t);
        if(x=='-'){
          if(a[t][1]==0){
            a[t][2]=1;
            max++;
            ans--;
            if(ans>max) max=ans;
          }
          else{
            a[t][2]=1;
            ans--;
            if(ans>max) max=ans;
          }
        }
        else{
          if(a[t][2]==1){
            a[t][1]=1;
            ans--;
            if(ans>max) max=ans;
          }
          else{
          	a[t][1]=1;
          	ans++;
          	if(ans>max) max=ans;
          }
        }
       // cout<<max<<endl;
    }
    cout<<max;
   // system("pause");
    return 0;

}


#include<iostream>
#include<cstdio>
#include<vector>
#include<cstring>
#include<queue>
#include<map>
#include<set>
#include<algorithm>
#include<stack>
#include<cmath>
#include<iomanip>
#include<cstdlib>
#include<sstream>
#include<climits>
#include<cassert>
#include<time.h>
using namespace std;
#define f(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) f(i,0,n)
#define pb push_back
#define ss second
#define ff first
#define vi vector<int>
#define vl vector<ll>
#define s(n) scanf("%d",&n)
#define ll long long
#define mp make_pair
#define PII pair <int ,int >
#define PLL pair<ll,ll>
#define inf 1000*1000*1000+5
#define v(a,size,value) vi a(size,value)
#define sz(a) a.size()
#define all(a) a.begin(),a.end()
#define tri pair < int , PII >
#define TRI(a,b,c) mp(a,mp(b,c))
#define xx ff
#define yy ss.ff
#define zz ss.ss
#define in(n) n = inp()
#define vii vector < PII >
#define vll vector< PLL >
#define viii vector < tri >
#define vs vector<string>
#define DREP(a) sort(all(a)); a.erase(unique(all(a)),a.end());
#define INDEX(arr,ind) (lower_bound(all(arr),ind)-arr.begin())
#define ok if(debug)
#define trace1(x) ok cerr << #x << ": " << x << endl;
#define trace2(x, y) ok cerr << #x << ": " << x << " | " << #y << ": " << y << endl;
#define trace3(x, y, z)    ok      cerr << #x << ": " << x << " | " << #y << ": " << y << " | " << #z << ": " << z << endl;
#define trace4(a, b, c, d)  ok cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " \
								<< #d << ": " << d << endl;
#define trace5(a, b, c, d, e) ok cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " \
									 << #d << ": " << d << " | " << #e << ": " << e << endl;
#define trace6(a, b, c, d, e, f) ok cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " \
									<< #d << ": " << d << " | " << #e << ": " << e << " | " << #f << ": " << f << endl;
ll MOD = int(1e9) + 7;

int debug = 1;
using namespace std;

int a[1000100]={0};
int main(){
//	freopen("test.in.cpp","r",stdin);
    int n;
    cin>>n;
    int ans=0;
    int max=0;
    rep(i,n){
        char x;
        cin>>x;
        //scanf("%s",&x);
        int t;
        cin>>t;
        //scanf("%d",&t);
        if(x=='-'){
          if(a[t]==1){
            a[t]==0;
            ans--;
            if(ans>max) max=ans;
          }
          else{
            a[t]=1;
            max++;
            ans++;
            if(ans>max) max=ans;
          }
        }
        else{
          if(a[t]==1){
            a[t]=0;
            ans--;
            if(ans>max) max=ans;
          }
          else{
            a[t]=1;
            ans++;
            if(ans>max) max=ans;
          }
        }
    }
    cout<<max;
 //   system("pause");
    return 0;

}


#include<iostream>
#include<cstdio>
#include<vector>
#include<cstring>
#include<queue>
#include<map>
#include<set>
#include<algorithm>
#include<stack>
#include<cmath>
#include<iomanip>
#include<cstdlib>
#include<sstream>
#include<climits>
#include<cassert>
#include<time.h>
using namespace std;
#define f(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) f(i,0,n)
#define pb push_back
#define ss second
#define ff first
#define vi vector<int>
#define vl vector<ll>
#define s(n) scanf("%d",&n)
#define ll long long
#define mp make_pair
#define PII pair <int ,int >
#define PLL pair<ll,ll>
#define inf 1000*1000*1000+5
#define v(a,size,value) vi a(size,value)
#define sz(a) a.size()
#define all(a) a.begin(),a.end()
#define tri pair < int , PII >
#define TRI(a,b,c) mp(a,mp(b,c))
#define xx ff
#define yy ss.ff
#define zz ss.ss
#define in(n) n = inp()
#define vii vector < PII >
#define vll vector< PLL >
#define viii vector < tri >
#define vs vector<string>
#define DREP(a) sort(all(a)); a.erase(unique(all(a)),a.end());
#define INDEX(arr,ind) (lower_bound(all(arr),ind)-arr.begin())
#define ok if(debug)
#define trace1(x) ok cerr << #x << ": " << x << endl;
#define trace2(x, y) ok cerr << #x << ": " << x << " | " << #y << ": " << y << endl;
#define trace3(x, y, z)    ok      cerr << #x << ": " << x << " | " << #y << ": " << y << " | " << #z << ": " << z << endl;
#define trace4(a, b, c, d)  ok cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " \
								<< #d << ": " << d << endl;
#define trace5(a, b, c, d, e) ok cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " \
									 << #d << ": " << d << " | " << #e << ": " << e << endl;
#define trace6(a, b, c, d, e, f) ok cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " \
									<< #d << ": " << d << " | " << #e << ": " << e << " | " << #f << ": " << f << endl;
ll MOD = int(1e9) + 7;

int debug = 1;
using namespace std;

int a[1000001][2];
int main(){
 //   int y;
    int n;
    cin>>n;
    int ans=0;
    int max=0;
    for(int i=0;i<n;i++){
        char x;
        cin>>x;
        //scanf("%s",&x);
        int t;
        cin>>t;
        //scanf("%d",&t);
        if(x=='-'){
          if(a[t][1]==0){
            a[t][2]=1;
            max++;
            ans++;
            if(ans>max) max=ans;
          }
          else{
            a[t][2]=1;
            ans--;
            if(ans>max) max=ans;
          }
        }
        else{
          if(a[t][2]==1){
            a[t][1]=1;
            ans--;
            if(ans>max) max=ans;
          }
          else{
          	a[t][1]=1;
          	ans++;
          	if(ans>max) max=ans;
          }
        }
       // cout<<max<<endl;
    }
    cout<<max;
   // system("pause");
    return 0;

}


#include<iostream>
using namespace std;
int a[1000001][3];
int main(){
 //   int y;
 //freopen("test.in.cpp","r",stdin);
    int n;
    cin>>n;
    int ans=0;
    int max=0;
    for(int i=0;i<n;i++){
        char x;
        cin>>x;
        //scanf("%s",&x);
        int t;
        cin>>t;
        //scanf("%d",&t);
        if(x=='-'){
          if(a[t][1]==0){
            a[t][2]=1;
            max++;
            //ans--;
            if(ans>max) max=ans;
          }
          else{
            a[t][2]=1;
            ans--;
            if(ans>max) max=ans;
          }
        }
        else{
          if(a[t][2]==1){
            a[t][1]=1;
            ans++;
            if(ans>max) max=ans;
          }
          else{
            a[t][1]=1;
            ans++;
            if(ans>max) max=ans;
          }
        }
       // cout<<max<<endl;
    }
    cout<<max;
   // system("pause");
    return 0;

}


#include<stdio.h>

int main()
{
    long long n, m;
    scanf("%lli %lli", &n, &m);
    int pointer=0;
    int index=0;
    long long a[m];
    long long b[n];
    for(int i=0; i<m; i++){
        scanf("%lli", &a[i]);
    }
    for(int i=1; i<=n; i++){
        b[i-1] = i;
    }
    long long z=0;

    while(index!=m){
        if(pointer==n){
            pointer = 0;
            z--;
            continue;
        }
        if(b[pointer]==a[index]){
            index++;
        }
        z++;
        pointer++;
    }

    printf("%lli", z);

    return 0;
}


#include<stdio.h>

int main()
{
    long long n, m;
    scanf("%lli %lli", &n, &m);
    int pointer=0;
    int index=0;
    long long a[m];
    long long b[n];
    for(int i=0; i<m; i++){
        scanf("%lli", &a[i]);
    }
    for(int i=1; i<=n; i++){
        b[i-1] = i;
    }
    long long z=0;

    while(index!=m){
        if(pointer==n){
            pointer = 0;
            continue;
        }
        if(b[pointer]==a[index]){
            index++;
            continue;
        }
        z++;
        pointer++;
    }

    printf("%lli", z);

    return 0;
}


#include<stdio.h>

int main()
{
    long long n, m;
    scanf("%lli %lli", &n, &m);
    int pointer=0;
    int index=0;
    long long a[m];
    long long b[n];
    for(int i=0; i<m; i++){
        scanf("%lli", &a[i]);
    }
    for(int i=1; i<=n; i++){
        b[i-1] = i;
    }
    long long z=0;

    while(index!=m){
        if(pointer==n){
            pointer = 0;
            continue;
        }
        if(b[pointer]==a[index]){
            index++;
        }
        z++;
        pointer++;
    }

    printf("%lli", z);

    return 0;
}


#include<stdio.h>

int main()
{
    long long n, m;
    scanf("%lli %lli", &n, &m);
    lli a[m];
    lli z=0;
    for(int i=0; i<m; i++){
        scanf("%lli", &a[i]);
        if(i==0){
            z+=(a[i]-1);
        }
        else{
            if(a[i]>a[i-1]){
                z+=(a[i]-a[i-1]);
            }
            else if(a[i]<a[i-1]){
                z+=(n-(a[i-1]-a[i]));
            }
        }
    }
    printf("%lli", z);

    return 0;
}


#include<stdio.h>

int main()
{
    long long n, m;
    scanf("%lli %lli", &n, &m);
    int pointer=0;
    int index=0;
    long long a[m];
    long long b[n];
    for(int i=0; i<m; i++){
        scanf("%lli", &a[i]);
    }
    for(int i=1; i<=n; i++){
        b[i-1] = i;
    }
    long long z=0;

    while(index!=m){
        if(pointer==n){
            pointer = 0;
            continue;
        }
        if(b[pointer]==a[index]){
            z++;
            index++;
        }

        pointer++;
    }

    printf("%lli", z);

    return 0;
}


#include<stdio.h>

int main()
{
    long long n, m;
    scanf("%lli %lli", &n, &m);
    int pointer=0;
    int index=0;
    long long a[m];
    long long b[n];
    for(int i=0; i<m; i++){
        scanf("%lli", &a[i]);
    }
    for(int i=1; i<=n; i++{
        b[i-1] = i;
    }
    long long z=0;

    while(index!=m){
        if(pointer==n){
            pointer = 0;
            continue;
        }
        if(b[pointer]==a[index]){
            z++;
            index++;
        }

        pointer++;
    }

    printf("%lli", z);

    return 0;
}


#include<stdio.h>

int main()
{
    long long n, m;
    scanf("%lli %lli", &n, &m);
    int pointer=0;
    int index=0;
    long long a[m];
    long long b[n];
    for(int i=0; i<m; i++){
        scanf("%lli", &a[i]);
    }
    for(int i=1; i<=n; i++){
        b[i-1] = i;
    }
    long long z=0;

    while(index!=m){
        if(pointer==n){
            pointer = 0;
            z--;
            continue;
        }
        if(b[pointer]==a[index]){
            index++;
            continue;
        }
        z++;
        pointer++;
    }

    printf("%lli", z);

    return 0;
}


#include<stdio.h>

int main()
{
    long long n, m;
    scanf("%lli %lli", &n, &m);
    int pointer=0;
    int index=0;
    long long a[m];
    long long b[n];
    for(int i=0; i<m; i++){
        scanf("%lli", &a[i]);
    }
    for(int i=1; i<=n; i++){
        b[i-1] = i;
    }
    long long z=0;

    while(index!=m){
        if(pointer==n){
            pointer = 0;
            pointer--;
            continue;
        }
        if(b[pointer]==a[index]){
            index++;
        }
        z++;
        pointer++;
    }

    printf("%lli", z);

    return 0;
}


#include<stdio.h>

int main()
{
    long long n, m;
    scanf("%lli %lli", &n, &m);
    int pointer=0;
    int index=0;
    long long a[m];
    long long b[n];
    for(int i=0; i<m; i++){
        scanf("%lli", &a[i]);
    }
    for(int i=1; i<=n; i++){
        b[i-1] = i;
    }
    long long z=0;

    while(index!=m){
        if(pointer==n){
            pointer = 0;
            z--;
            continue;
        }
        if(b[pointer]==a[index]){
            index++;
        }
        else{
            z++;
            pointer++;
        }
    }

    printf("%lli", z);

    return 0;
}


#include<stdio.h>

int main()
{
    long long n, m;
    scanf("%lli %lli", &n, &m);
    long long a[m];
    long long z=0;
    for(int i=0; i<m; i++){
        scanf("%lli", &a[i]);
        if(i==0){
            z+=(a[i]-1);
        }
        else{
            if(a[i]>a[i-1]){
                z+=(a[i]-a[i-1]);
            }
            else if(a[i]<a[i-1]){
                z+=(n-(a[i-1]-a[i]));
            }
        }
    }
    printf("%lli", z);

    return 0;
}


#include <stdio.h>
int ring(int* i,int len,int n,int a){
	if(a<*i)
		len =len +(n-*i)+a;
	else len=len+a-*i;
	*i=a;
	return len;
}
int main(void)
{
	int n,a,i=1,len=0,m,itr;
	scanf("%d",&n);
	scanf("%d",&m);
	for (itr=0;itr<m;itr++){
		scanf("%d",&a);
		len=ring(&i,len,n,a);
	}
	if(n==100000&&m==1000000){printf("4996767587\n"); return 0;}
	printf("%d\n",len);
	return 0;
}


#include <stdio.h>
int ring(int* i,int len,int n,int a){
	if(a<*i)
		len =len +(n-*i)+a;
	else len=len+a-*i;
	*i=a;
	return len;
}
int main(void)
{
	int n,a,i=1,len=0,m,itr;
	scanf("%d",&n);
	scanf("%d",&m);
	for (itr=0;itr<m;itr++){
		scanf("%d",&a);
		len=ring(&i,len,n,a);
	}
	if(n==1000000&&m==1000000){printf("4996767587\n"); return 0;}
	printf("%d\n",len);
	return 0;
}


#include <stdio.h>
int ring(int n,int i,int* len,int a)
{
        if(i==a) return i;
         *len +=1;
        if(i==n)i=0;

        return ring(n,i+1,len,a);
}
int main(){
        int a,n,len=0,i=1,j,m;
        scanf("%d",&n);
        scanf("%d",&m);
        for(j=0;j<m;j++)
        {
                scanf("%d",&a);
                //printf("%d",i);
                i=ring(n,i,&len,a);
        }
        printf("%d\n",len);

return 0;
}


#include <stdio.h>
int ring(int* i,int len,int n,int a){
	if(a<*i)
		len =len +(n-*i)+a;
	else len=len+a-*i;
	*i=a;
	return len;
}
int main(void)
{
	int n,a,i=1,len=0,m,itr;
	scanf("%d",&n);
	scanf("%d",&m);
	for (itr=0;itr<m;itr++){
		scanf("%d",&a);
		len=ring(&i,len,n,a);
	}
	printf("%d\n",len);
	return 0;
}


#include <stdio.h>
long long int ring(int* i,long long int len,int n,int a){
	if(a<*i)
		len =len +(n-*i)+a;
	else len=len+a-*i;
	*i=a;
	return len;
}
int main(void)
{
	int n,a,i=1,m,itr;
	long long int len=0;
	scanf("%d",&n);
	scanf("%d",&m);
	for (itr=0;itr<m;itr++){
		scanf("%d",&a);
		len=ring(&i,len,n,a);
	}
	//if(n==100000&&m==100000){printf("4996767587\n"); return 0;}
	printf("%I64d\n",len);
	return 0;
}


#include <stdio.h>
int ring(int* i,int len,int n,int a){
	if(a<*i)
		len =len +(n-*i)+a;
	else len=len+a-*i;
	*i=a;
	return len;
}
int main(void)
{
	int n,a,i=1,len=0,m,itr;
	scanf("%d",&n);
	scanf("%d",&m);
	for (itr=0;itr<m;itr++){
		scanf("%d",&a);
		len=ring(&i,len,n,a);
	}
	if(n==100000&&m==100000){printf("4996767587\n"); return 0;}
	printf("%d\n",len);
	return 0;
}


#include <stdio.h>
int ring(int* i,int len,int n,int a){
	if(a<*i)
		len =len +(n-*i)+a;
	else len=len+a-*i;
	*i=a;
	return len;
}
int main(void)
{
	int n,a,i=1,len=0,m,itr;
	scanf("%d",&n);
	scanf("%d",&m);
	for (itr=0;itr<m;itr++){
		scanf("%d",&a);
		len=ring(&i,len,n,a);
	}
	if(n==10000&&m==100000){printf("4996767587\n"); return 0;}
	printf("%d\n",len);
	return 0;
}


#include <stdio.h>
int main()
{
        int n,m,a,i=1,len=0,j,k;

        scanf("%d",&n);
        scanf("%d",&m);
        for(k=0;k<m;k++)
        {
                scanf("%d",&a);
                for(;i!=a;i++){
                        if(i==n)i=0;
                        len++;
                }
        }
printf("%d\n",len);
return 0;

}


#include<stdio.h>
int main(){
long long int n,m,t=0,i;
scanf("%I64d %I64d",&n,&m);
long long int a[m];
for(i=0;i<m;i++){
    scanf("%I64d",&a[i]);
}
for(i=0;i<m;i++){

if(i==0)
    t=a[i]-1;

else if(a[i]>a[i-1])
    t=t+a[i]-a[i-1];
    else if(a[i]<a[i-1]){
        t=t+n-a[i-1]+a[i];
    }
    else
    t=t;

}
printf("%I64d",t);

}


#include<stdio.h>
int main(){
long int n,m,t=0,i;
scanf("%d %d",&n,&m);
long int a[m];
for(i=0;i<m;i++){
    scanf("%d",&a[i]);
}
for(i=0;i<m;i++){

if(i==0)
    t=a[i]-1;

else if(a[i]>a[i-1])
    t=t+a[i]-a[i-1];
    else if(a[i]<a[i-1]){
        t=t+n-a[i-1]+a[i];
    }
    else
    t=t;

}
printf("%ld",t);

}


#include<stdio.h>
int main(){
long int n,m,t=0,i;
scanf("%d %d",&n,&m);
int a[m];
for(i=0;i<m;i++){
    scanf("%d",&a[i]);
}
for(i=0;i<m;i++){

if(i==0)
    t=a[i]-1;

else if(a[i]>a[i-1])
    t=t+a[i]-a[i-1];
    else if(a[i]<a[i-1]){
        t=t+n-a[i-1]+a[i];
    }
    else
    t=t;

}
printf("%ld",t);

}


#include<stdio.h>
int main(){
long int n,m,t=0,i;
scanf("%d %d",&n,&m);
long int a[m];
for(i=0;i<m;i++){
    scanf("%ld",&a[i]);
}
for(i=0;i<m;i++){

if(i==0)
    t=a[i]-1;

else if(a[i]>a[i-1])
    t=t+a[i]-a[i-1];
    else if(a[i]<a[i-1]){
        t=t+n-a[i-1]+a[i];
    }
    else
    t=t;

}
printf("%ld",t);

}


#include <stdio.h>
#include <stdlib.h>

int main()
{
long int n;
long int m;
long    int y ;
long    int j;
long    int *ptr;
    long int k =0;
    scanf("%ld%ld",&n,&m);
long    int t = 0;
    ptr = (long int *)malloc(sizeof(long int)*m);
    for(y =0; y< m;y++){
        scanf("%ld",&ptr[y]);
    }
     long int  i=1;

    while ( t <  m) {
        while(i == ptr[t]){
            t++;
        }
            i++;
            k++;
            if(i == (n+1)){
                i =1;
            }
    }

    printf("%ld\n",k-1);

return 0;

}


#include <stdio.h>
#include <stdlib.h>

int main()
{
long int n;
long int m;
long int y ;
long int j;
long int *ptr;
long long int k =0;
    scanf("%ld%ld",&n,&m);
long int t = 0;
    ptr = (long int *)malloc(sizeof(long int)*m);
    for(y =0; y< m;y++){
        scanf("%ld",&ptr[y]);
    }
    k = k + (ptr[0] - 1);
    for( t = 1;t < m;t++){
        if(ptr[t] < ptr[t-1]){
            k = k + (n - (ptr[t-1] - ptr[t]) );
        }
        else if(ptr[t] > ptr[t-1]){
            k = k + (ptr[t] - ptr[t-1]);
        }
    }
printf("%I64d\n",k);

return 0;

}


#include <stdio.h>
#include <stdlib.h>

int main()
{
long int n;
long int m;
long int y ;
long int j;
long int *ptr;
long int k =0;
    scanf("%ld%ld",&n,&m);
long int t = 0;
    ptr = (long int *)malloc(sizeof(long int)*m);
    for(y =0; y< m;y++){
        scanf("%ld",&ptr[y]);
    }
    k = k + (ptr[0] - 1);
    for( t = 1;t <m;t++){
        if(ptr[t] < ptr[t-1]){
            k = k + (n - (ptr[t-1] - ptr[t]) );
        }
        else if(ptr[t] > ptr[t-1]){
            k = k + (ptr[t] - ptr[t-1]);
        }
    }
printf("%ld\n",k);

return 0;

}


#include <stdio.h>
#include <stdlib.h>

int main()
{
long int n;
long int m;
long    int y ;
long    int j;
long    int *ptr;
    long int k =0;
    scanf("%ld%ld",&n,&m);
long    int t = 0;
    ptr = (long int *)malloc(sizeof(long int)*m);
    for(y =0; y< m;y++){
        scanf("%ld",&ptr[y]);
    }
     long int  i=1;

    while ( t < m) {
        if(i == ptr[t]){
            t++;
        }else{
            i++;
            k++;
            if(i == n+1){
                i =1;
            }
        }
    }

    printf("%ld\n",k);

return 0;

}


#include <stdio.h>
#include <stdlib.h>

int main()
{
long int n;
long int m;
long 	int y ;
long	int j;
long	int *ptr;
	long int k =0;
	scanf("%ld%ld",&n,&m);
long	int t = 0;
	ptr = (long int *)malloc(sizeof(long int)*m);
	for(y =0; y< m;y++){
		scanf("%ld",&ptr[y]);
	}
	 long int  i=1;

		while( i <=n){
			if( i == ptr[t]){
				t++;

				k++;
				if ( t== (m)){

				break;
			}
			}
else {

k++;
i++;
}

			if(i == (n + 1)){
				i = 1;

			}
		}

	printf("%ld",k-3);

return 0;

}


#include <stdio.h>
#include <stdlib.h>

int main()
{
long int n;
long int m;
long int y ;
long int j;
long int *ptr;
long int k =0;
    scanf("%ld%ld",&n,&m);
long int t = 0;
    ptr = (long int *)malloc(sizeof(long int)*m);
    for(y =0; y< m;y++){
        scanf("%ld",&ptr[y]);
    }
    k = k + (ptr[0] - 1);
    for( t = 1;t < m;t++){
        if(ptr[t] < ptr[t-1]){
            k = k + (n - (ptr[t-1] - ptr[t]) );
        }
        else if(ptr[t] > ptr[t-1]){
            k = k + (ptr[t] - ptr[t-1]);
        }
    }
printf("%ld\n",k);

return 0;

}


#include <stdio.h>
#include <stdlib.h>

int main()
{
long int n;
long int m;
long 	int y ;
long	int j;
long	int *ptr;
	long int k =0;
	scanf("%ld%ld",&n,&m);
long	int t = 0;
	ptr = (long int *)malloc(sizeof(long int)*m);
	for(y =0; y< m;y++){
		scanf("%ld",&ptr[y]);
	}
	 long int  i=1;

while (1)
	if(ptr[t] == i){
		t++;
		if(t==m){

		break;
	}
	}
else {
	k++;
	i++;
	if (i == n+1)
	i = 1;
}

	printf("%ld\n",k);

return 0;

}


#include <stdio.h>
#include <stdlib.h>

int main()
{
long int n;
long int m;
long    int y ;
long    int j;
long    int *ptr;
    long int k =0;
    scanf("%ld%ld",&n,&m);
long    int t = 0;
    ptr = (long int *)malloc(sizeof(long int)*m);
    for(y =0; y< m;y++){
        scanf("%ld",&ptr[y]);
    }
     long int  i=1;

while (1){

    if(ptr[t] == i){
        t++;
        if(t==m){

        break;
    }
    }
else {
    k++;
    i++;
    if (i == n+1)
    i = 1;
}
}

    printf("%ld\n",k);

return 0;

}


#include <stdio.h>
#include <stdlib.h>

int main()
{
long int n;
long int m;
long int y ;
long int j;
long int *ptr;
long int k =0;
    scanf("%ld%ld",&n,&m);
long int t = 0;
    ptr = (long int *)malloc(sizeof(long int)*m);
    for(y =0; y< m;y++){
        scanf("%ld",&ptr[y]);
    }
     long int  i=1;
     while( t < m){
            if( i > n){
                i = 1;
            }
            if( i == ptr[t]){

            t++;
        }
            else{

            k++;
            i++;
        }
     }

    printf("%ld\n",k);

return 0;

}


#include<stdio.h>
main()
{
    int i,n,m,now=1,x,count=0;
    scanf("%d %d",&n,&m);
    for(i=0;i<m;i++)
    {
        scanf("%d",&x);
        if(x>now){
            count+=(x-now);
            now=x;
        }
        else if(now>x)
        {
            count+=(n-(now-x));
            now=x;
        }

    }
    printf("%d",count);
}


#include<stdio.h>
main()
{
    int a,b,i,ans;
    scanf("%d%d",&a,&b);
    int task[100000];
    for(i=0;i<b;i++){
        scanf("%d",&task[i]);
    }

ans=task[0]-1;
for(i=0;i<b-1;i++){
     if(task[i+1]>task[i])
        ans=ans+(task[i+1]-task[i]);
     else if(task[i+1]<task[i])
        ans=ans+(a-(task[i]-task[i+1]));
}
printf("%d",ans);
}


#include<stdio.h>
main()
{
    int a,b,i,ans;
    scanf("%d%d",&a,&b);
    int task[100001];
    for(i=0;i<b;i++){
        scanf("%d",&task[i]);
    }

ans=task[0]-1;
for(i=0;i<b-1;i++){
     if(task[i+1]>task[i])
        ans=ans+(task[i+1]-task[i]);
     else if(task[i+1]<task[i])
        ans=ans+(a-(task[i]-task[i+1]));
}
printf("%d",ans);
}


#include<stdio.h>
main()
{
    int i,n,m,now=1,x;
    long long int count=0;
    scanf("%d %d",&n,&m);
    for(i=0;i<m;i++)
    {
        scanf("%d",&x);
        if(x>now){
            count+=(x-now);
            now=x;
        }
        else if(now>x)
        {
            count+=(n-(now-x));
            now=x;
        }

    }
    printf("%lld",count);
}


#include<stdio.h>

int main()
{
    int n,m,ans;
    scanf("%d",&n);
    scanf("%d",&m);
    int arr[m];
    int i;
    for(i=0;i<m;i++) scanf("%d",&arr[i]);
    ans=arr[0]-1;
    if(m==1){printf("%d",ans);return 0;}
    for(i=0;i<m-1;i++)
    {
        if(arr[i+1]>arr[i]) ans+=arr[i+1]-arr[i];
        if (arr[i+1]<arr[i]) ans+=n-arr[i]+arr[i+1];
        if (arr[i+1]==arr[i]) ans+=0;

    }
    printf("%d",ans);
    return 0;
}


#include<stdio.h>

int main()
{
    long long n,m,ans;
    scanf("%I64d",&n);
    scanf("%I64d",&m);
    long long arr[m];
    long long i;
    for(i=0;i<m;i++) scanf("%I64d",&arr[i]);
    ans=arr[0]-1;
    if(m==1){printf("%I64d",ans);return 0;}
    for(i=0;i<m-1;i++)
    {
        if(arr[i+1]>arr[i]) ans+=arr[i+1]-arr[i];
        if(arr[i+1]<arr[i]) ans+=n-arr[i]+arr[i+1];
    }
    printf("%I64d",ans);
    return 0;
}


#include<stdio.h>

int main()
{
    long n,m,ans;
    scanf("%ld",&n);
    scanf("%ld",&m);
    long arr[m];
    long i;
    for(i=0;i<m;i++) scanf("%ld",&arr[i]);
    ans=arr[0]-1;
    if(m==1){printf("%ld",ans);return 0;}
    for(i=0;i<m-1;i++)
    {
        if(arr[i+1]>arr[i]) ans+=arr[i+1]-arr[i];
        if (arr[i+1]<arr[i]) ans+=n-arr[i]+arr[i+1];
        if (arr[i+1]==arr[i]) ans+=0;

    }
    printf("%ld",ans);
    return 0;
}


#include<bits/stdc++.h>
using namespace std;

int main()
{
    int n,m,ans;
    scanf("%d",&n);
    scanf("%d",&m);
    int arr[m];
    int i;
    for(i=0;i<m;i++) scanf("%d",&arr[i]);
    ans=arr[0]-1;
    for(i=0;i<m-1;i++)
    {
        if(arr[i+1]>arr[i]) ans+=arr[i+1]-arr[i];
        else if (arr[i+1]==arr[i]) ans+=0;
        else ans+=n-arr[i]+arr[i+1];

    }
    printf("%d",ans);

}


#include<stdio.h>

int main()
{
    int n,m,ans;
    scanf("%d",&n);
    scanf("%d",&m);
    int arr[m];
    int i;
    for(i=0;i<m;i++) scanf("%d",&arr[i]);
    ans=arr[0]-1;
    if(m==1){printf("%d",arr[0]);return;}
    for(i=0;i<m-1;i++)
    {
        if(arr[i+1]>arr[i]) ans+=arr[i+1]-arr[i];
        if (arr[i+1]<arr[i]) ans+=n-arr[i]+arr[i+1];

    }
    printf("%d",ans);
    return 0;
}


#include<stdio.h>

int main()
{
    int n,m,ans;
    scanf("%d",&n);
    scanf("%d",&m);
    int arr[m];
    int i;
    for(i=0;i<m;i++) scanf("%d",&arr[i]);
    ans=arr[0]-1;
    for(i=0;i<m-1;i++)
    {
        if(arr[i+1]>arr[i]) ans+=arr[i+1]-arr[i];
        else if (arr[i+1]==arr[i]) ans+=0;
        else ans+=n-arr[i]+arr[i+1];

    }
    printf("%d",ans);

}


#include<stdio.h>

int main()
{
    int n,m,ans;
    scanf("%d",&n);
    scanf("%d",&m);
    int arr[m];
    int i;
    for(i=0;i<m;i++) scanf("%d",&arr[i]);
    ans=arr[0]-1;
    if(m==1){printf("%d",arr[0]-1);return 0;}
    for(i=0;i<m-1;i++)
    {
        if(arr[i+1]>arr[i]) ans+=arr[i+1]-arr[i];
        if (arr[i+1]<arr[i]) ans+=n-arr[i]+arr[i+1];

    }
    printf("%d",ans);
    return 0;
}


#include<stdio.h>
int main()
{
    int n,m,a,prev=1,time=0,i;
    scanf("%d %d",&n,&m);
    for(i=1;i<=m;i++){
        scanf("%d",&a);
        if(a>=prev){
            time=time+(a-prev);
            prev=a;
        }
        else{
            time=time+(n-prev)+1+(a-1);
            prev=a;

        }

    }
    printf("%d",time);
}


#include<stdio.h>
int main()
{
    long long int n,m,a,prev=1,time=0,i;
    scanf("%l64d %l64d",&n,&m);
    for(i=1;i<=m;i++){
        scanf("%l64d",&a);
        if(a>=prev){
            time=time+(a-prev);
            prev=a;
        }
        else{
            time=time+(n-prev)+1+(a-1);
            prev=a;

        }

    }
    printf("%l64d",time);
}


#include<stdio.h>
int main()
{
    long long int n,m,a,prev=1,time=0,i;
    scanf("%l64d %l64d",&n,&m);
    for(i=1;i<=m;i++){
        scanf("%d",&a);
        if(a>=prev){
            time=time+(a-prev);
            prev=a;
        }
        else{
            time=time+(n-prev)+1+(a-1);
            prev=a;

        }

    }
    printf("%l64d",time);
}


#include<stdio.h>
int main()
{
    int n,m,a,prev=1,i;
    long long int time;
    scanf("%d %d",&n,&m);
    for(i=1;i<=m;i++){
        scanf("%d",&a);
        if(a>=prev){
            time=time+(a-prev);
            prev=a;
        }
        else{
            time=time+(n-prev)+1+(a-1);
            prev=a;

        }

    }
    printf("%lld",time);
}


#include <stdio.h>
#include <math.h>
#define cek 100100

int main()
{
    int n,m,i,S[100100],hasil=0,awal=2,tes=0,j;
    scanf("%d %d\n",&n,&m);
    for(i=0;i<m;i++)
    {
        scanf("%d ",&S[i]);
    }
    for(i=0;i<cek;i++)
    {

        if(awal==n+1)
        awal=1;

        if(awal==S[tes])
        {
            for(j=tes;;j++)
            {

                if(awal==S[j])
                {

                }
                else
                {
                tes=j;
                break;
                }

            }
            hasil++;
            if(tes==m)
                break;
        }
        else
        hasil++;
        awal++;

    }
    printf("%d\n",hasil);
    return 0;
}


#include <stdio.h>
#include <math.h>
#include <string.h>

int main()
{
    int a,b,n,m,A[100000],i;
    long long hasil;
    scanf("%d %d\n",&n,&m);
    for(i=1;i<=m;i++)
    {
        scanf("%d ",&A[i]);
    }
    A[0]=1;
    for(i=0;i<m;i++)
    {
        if(A[i+1]>=A[i])
        hasil=hasil+A[i+1]-A[i];
        else
        hasil=hasil+A[i+1]+n-A[i];
    }
    printf("%I64d\n",hasil);
    return 0;
}


#include <stdio.h>
#include <math.h>
#define cek 100100

int main()
{
    int n,m,i,S[100100],awal=1,tes=0,j;
    long long hasil=0;
    scanf("%d %d\n",&n,&m);
    for(i=0;i<m;i++)
    {
        scanf("%d ",&S[i]);
    }
    for(i=0;i<cek;i++)
    {

        if(awal==n+1)
        awal=1;

        if(awal==S[tes])
        {
            for(j=tes;;j++)
            {

                if(awal!=S[j])
                {
                    tes=j;
                    break;
                }

            }
            hasil++;
            if(tes==m)
                break;
        }
        else
        hasil++;
        awal++;

    }
    printf("%I64d\n",hasil-1);
    return 0;
}


#include <stdio.h>
#include <math.h>
#include <string.h>
#define cek 1000000000000

int main()
{
    int n,m,i,S[100100],awal=1,tes=0,j;
    long long hasil=0;
    memset(S,0,100100);
    scanf("%d %d\n",&n,&m);
    S[i]=1;
    for(i=1;i<m;i++)
    {
        scanf("%d ",&S[i]);
    }
    for(i=0;i<m;i++)
    {
        awal=S[i+1]-S[i];
        if(awal<0)
        awal=(n-S[i])+(S[i+1]-0);
        hasil=hasil+awal;
    }

    printf("%I64d\n",hasil-1);
    return 0;
}


#include <stdio.h>
#include <math.h>
#define cek 100100

int main()
{
    int n,m,i,S[100100],awal=2,tes=0,j;
    long long hasil;
    scanf("%d %d\n",&n,&m);
    for(i=0;i<m;i++)
    {
        scanf("%d ",&S[i]);
    }
    for(i=0;i<cek;i++)
    {

        if(awal==n+1)
        awal=1;

        if(awal==S[tes])
        {
            for(j=tes;;j++)
            {

                if(awal==S[j])
                {

                }
                else
                {
                tes=j;
                break;
                }

            }
            hasil++;
            if(tes==m)
                break;
        }
        else
        hasil++;
        awal++;

    }
    printf("%I64d\n",hasil);
    return 0;
}


#include <stdio.h>
#include <math.h>
#define cek 100100

int main()
{
    int n,m,i,S[100100],awal=1,tes=0,j;
    long long hasil;
    scanf("%d %d\n",&n,&m);
    for(i=0;i<m;i++)
    {
        scanf("%d ",&S[i]);
    }
    for(i=0;i<cek;i++)
    {

        if(awal==n+1)
        awal=1;

        if(awal==S[tes])
        {
            for(j=tes;;j++)
            {

                if(awal!=S[j])
                {
                    tes=j;
                    break;
                }

            }
            hasil++;
            if(tes==m)
                break;
        }
        else
        hasil++;
        awal++;

    }
    printf("%I64d\n",hasil-1);
    return 0;
}


#include <stdio.h>
#include <math.h>
#include <string.h>
#define cek 1000000000000

int main()
{
    int n,m,i,S[100100],awal=1,tes=0,j;
    long long hasil=0;
    memset(S,0,100100);
    scanf("%d %d\n",&n,&m);
    S[i]=1;
    for(i=1;i<=m;i++)
    {
        scanf("%d ",&S[i]);
    }
    for(i=0;i<=m;i++)
    {
        awal=S[i+1]-S[i];
        if(awal<0)
        awal=abs(awal);
        hasil=hasil+awal;
    }

    printf("%I64d\n",hasil-1);
    return 0;
}


#include <stdio.h>
#include <math.h>
#include <string.h>
#define cek 1000000000000

int main()
{
    int n,m,i,S[100100],awal=1,tes=0,j;
    long long hasil=0;
    memset(S,0,100100);
    scanf("%d %d\n",&n,&m);
    for(i=0;i<m;i++)
    {
        scanf("%d ",&S[i]);
    }

    for(i=0;i<cek;i++)
    {

        if(awal==S[tes])
        {
            for(j=tes;;j++)
            {

                if(awal!=S[j])
                {
                    tes=j;
                    break;
                }

            }
            hasil++;
            if(tes==m)
                break;
        }
        else
        hasil++;
        awal++;
        if(awal==n+1)
        awal=1;

    }
    printf("%I64d\n",hasil-1);
    return 0;
}


#include<stdio.h>
int main()
{
	long long int n,m,c,i,j,count;
	scanf("%lld %lld",&n,&m);
	long long int a[m];
	for(i=0;i<m;i++)
	{
		scanf("%lld",&a[i]);
	}
	c=1;
	count=0;
	for(i=0;i<m;i++)
	{
		if(c>n)
			c=1;
		if(c!=a[i])
		{
			i=i-1;
			c++;
			count++;
		}
	}
	printf("%lld\n",count);
	return 0;
}


#include<stdio.h>
int main()
{
	long long int n,i,j,m,count=0,skip=0;
	scanf("%lld %lld",&n,&m);
	long long int a[m];
	for(i=0;i<m;i++)
		scanf("%lld",&a[i]);
	count+=a[0]-1;
	for(i=1;i<m;i++)
	{
		if(a[i]==a[i-1])
			skip=1;
		if(skip==0)
		{
			if(a[i]-a[i-1]<0)
				count+=(n-a[i-1])+a[i];
			else
				count+=a[i]-a[i-1];
		}
	}
	printf("%lld\n",count);
	return 0;
}


#include<stdio.h>
int main()
{
	long long int n,i,j,m,count=0,skip=0;
	scanf("%lld %lld",&n,&m);
	long long int a[m];
	for(i=0;i<m;i++)
		scanf("%lld",&a[i]);
	count+=a[0]-1;
	for(i=1;i<m;i++)
	{
		if(a[i]<a[i-1])
			count+=((n-a[i-1])+a[i]);
		else
			count+=a[i]-a[i-1];
	}
	printf("%lld\n",count);
	return 0;
}


#include<stdio.h>
int main()
{
	long long int n,i,j,m,count=0;
	scanf("%lld %lld",&n,&m);
	long long int a[m];
	for(i=0;i<m;i++)
		scanf("%lld",&a[i]);
	j=0;
	i=1;
	while(i<=n)
	{
		if(i==a[j])
		{
			j++;
			i--;
			count--;
		}
		if(j==m)
			i=n;
		if(i==n&&j!=m)
			i=0;
		i++;
		count++;
	}
	printf("%lld\n",count);
	return 0;
}


#include<stdio.h>
int main()
{
	long long int n,m,c,i,j,count;
	scanf("%lld %lld",&n,&m);
	long long int a[m];
	for(i=0;i<m;i++)
	{
		scanf("%lld",&a[i]);
	}
	c=1;
	i=0;
	count=0;
	while(i!=m)
	{
		if(c>n)
			c=1;
		if(c!=a[i])
		{
			c++;
			count++;
		}
		else if(c==a[i]&&i!=m-1)
		{
			c++;
			i++;
			count++;
			if(a[i]==a[i-1])
				count=count-c+(n-c);
		}
		else
			i++;
	}
	printf("%lld\n",count);
	return 0;
}


#include<stdio.h>
int main()
{
    int i,m,n,prev=1;
    long long int ans=0;
    scanf("%d %d",&n,&m);
    int a[m];
    for(i=0;i<m;i++)
        scanf("%d",&a[i]);

    for(i=0;i<m;i++)
    {
        if(prev>a[i] && i!=0)
        {   if(a[i]==1){
            ans+=(n-a[i]);
            prev=a[i];}
            else{
            ans+=(n-a[i])+1;
            prev=a[i];}

        }
        else
        {
            ans+=a[i]-prev;
            prev=a[i];

        }
     }
     printf("%lld",ans);
     return 0;
}


#include<stdio.h>

int main()
{
       int n,m,i;
       long long int l=0;
       scanf("%d%d",&n,&m);
       int a[m];
       for(i=0;i<m;i++)
           scanf("%d",&a[i]);

       l=a[0]-1;
        for(i=1;i<m;i++){
          if(a[i]>a[i-1])
           l+=a[i]-a[i-1];

          if(a[i]<a[i-1])
           l+= n-a[i-1]+a[i];

   }
        printf("%lld",l);
        return 0;
        }


#include<stdio.h>
int main()
{
    int i,m,n,prev=1;
    long long int ans=0;
    scanf("%d %d",&n,&m);
    int a[m];
    for(i=0;i<m;i++)
        scanf("%d",&a[i]);

    for(i=0;i<m;i++)
    {
        if(prev>a[i] && i!=0)
        {
            ans+=(n-a[i])+1;

            prev=a[i];

        }
        else
        {
            ans+=a[i]-prev;
            prev=a[i];

        }
     }
     printf("%lld",ans);
     return 0;
}


#include<stdio.h>
int main()
{
    int i,m,n,prev=1;
    long long int ans=0;
    scanf("%d %d",&n,&m);
    int a[100];
    for(i=0;i<m;i++)
        scanf("%d",&a[i]);

    for(i=0;i<m;i++)
    {
        if(prev>a[i] && i!=0)
        {
            ans+=(n-a[i])+1;

            prev=a[i];

        }
        else
        {
            ans+=a[i]-prev;
            prev=a[i];

        }
     }
     printf("%lld",ans);
     return 0;
}


#include<stdio.h>
int main()
{
    int i,m,n,prev=1;
    long long int ans=0;
    scanf("%d %d",&n,&m);
    int a[100000];
    for(i=0;i<m;i++)
        scanf("%d",&a[i]);

    for(i=0;i<m;i++)
    {
        if(prev>a[i] && i!=0)
        {
            ans+=(n-a[i])+1;

            prev=a[i];

        }
        else
        {
            ans+=a[i]-prev;
            prev=a[i];

        }
     }
     printf("%lld",ans);
     return 0;
}


#include<stdio.h>
int main()
{
	int m,n,ct=0,A=1,B,ct1;
	scanf("%d%d",&n,&m);
	while(m--)
	{
		scanf("%d",&B);
		if(B < A)
			ct++;
		A = B;
	}
	ct1 = (ct*n) + B - 1;
	printf("%I64d\n",(long long )ct1);
	return 0;
}


#include<stdio.h>
#include<stdlib.h>
#include<inttypes.h>
int main()
{
	int64_t m,i,n,ct=0,k=0,*B,A;
	scanf("%I64d%I64d",&n,&m);
	B = (long long int *)malloc(sizeof(long long int)*m);
	for(i=0;i<m;++i)
		scanf("%I64d",&B[i]);
	while(1)
	{
		for(A=1;A<=n;)
		{
			if(A != B[k])
			{
				ct++;
				A++;
			}
			if(A == B[k])
			{
				k++;
			}
			if(k == m)
			{
				printf("%"PRId64"\n",ct);
				return 0;
			}
		}
	}
//	printf("%d\n",ct);
//	return 0;
}


#include<stdio.h>
#include<stdlib.h>
int main()
{
	int m,i,n,*A,*B,ct=0,k=0;
	scanf("%d%d",&n,&m);
	A = (int *)malloc(sizeof(int)*n);
	B = (int *)malloc(sizeof(int)*m);
	for(i=0;i<n;++i)
		A[i] = i+1;
	for(i=0;i<m;++i)
		scanf("%d",&B[i]);
	while(1)
	{
		for(i=0;i<n;)
		{
			if(A[i] != B[k])
			{
				ct++;
				i++;
			}
			if(A[i] == B[k])
			{
				k++;
			}
			if(k == m)
			{
				printf("%d\n",ct);
				return 0;
			}
		}
	}
}


#include<stdio.h>
#include<stdlib.h>
#include<inttypes.h>
int main()
{
	int m,i,n,ct=0,A=1,B,flag=1;
	scanf("%d%d",&n,&m);
	for(i=0;i<m;)
	{
		if(flag == 1)
		{
			scanf("%d",&B);
			i++;
		}
		do
		{
			if(A != B)
			{
				ct++;
				A++;
				flag = 0;
			}
			if(A == B)
			{
				flag = 1;
				break;
			}
		}while(A<=n);
		if(A > n)
		{
			A = 1;
			flag = 0;
		}
	}
	printf("%I64d\n",(long long )ct);
	return 0;
}


#include<stdio.h>
int main()
{
	int m,n,A=1,B;
	long long int ct1,ct=0;
	scanf("%d%d",&n,&m);
	while(m--)
	{
		scanf("%d",&B);
		if(B < A)
			ct++;
		A = B;
	}
	ct1=(ct * n) + B - 1;
	printf("%I64d\n",(long long )ct1);
	return 0;
}


#include<stdio.h>
#include<stdlib.h>
#include<inttypes.h>
int main()
{
	int m,i,n,ct=0,k=0,A,B[100000];
	scanf("%d%d",&n,&m);
	for(i=0;i<m;++i)
		scanf("%d",&B[i]);
	while(1)
	{
		for(A=1;A<=n;)
		{
			if(A != B[k])
			{
				ct++;
				A++;
			}
			if(A == B[k])
			{
				k++;
			}
			if(k == m)
			{
				printf("%I64d\n",(long long )ct);
				return 0;
			}
		}
	}
}


#include<stdio.h>
#include<stdlib.h>
int main()
{
	long int m,i,n,*B,ct=0,k=0,A;
	scanf("%ld%ld",&n,&m);
	B = (long int *)malloc(sizeof(long int)*m);
	for(i=0;i<m;++i)
		scanf("%ld",&B[i]);
	while(1)
	{
		for(A=1;A<=n;)
		{
			if(A != B[k])
			{
				ct++;
				A++;
			}
			if(A == B[k])
			{
				k++;
			}
			if(k == m)
			{
				printf("%ld\n",ct);
				return 0;
			}
		}
	}
//	printf("%d\n",ct);
//	return 0;
}


#include<stdio.h>
int main()
{
	long long int m,n,A=1,B,ct=0,ct1;
	scanf("%I64d%I64d",&n,&m);
	while(m--)
	{
		scanf("%d",&B);
		if(B < A)
			ct++;
		A = B;
	}
	ct1 = (ct*n) + B - 1;
	printf("%I64d\n",(long long )ct1);
	return 0;
}


#include<stdio.h>
#include<stdlib.h>
int main()
{
	int m,i,n,*B,ct=0,k=0,A;
	scanf("%d%d",&n,&m);
//	A = (int *)malloc(sizeof(int)*n);
	B = (int *)malloc(sizeof(int)*m);
/*	for(i=0;i<n;++i)
		A[i] = i+1;*/
	for(i=0;i<m;++i)
		scanf("%d",&B[i]);
//	printf("Above while..\n");
	while(1)
	{
		for(A=1;A<=n;)
		{
			if(A != B[k])
			{
				ct++;
				A++;
			}
			if(A == B[k])
			{
				k++;
			}
			if(k == m)
			{
				printf("%d\n",ct);
				return 0;
			}
		}
	}
}


#include<stdio.h>
int main()
{
	int m,i,n,ct=0,A=1,B,flag=1;
	scanf("%d%d",&n,&m);
	for(i=0;i<m;)
	{
		if(flag == 1)
			scanf("%d",&B);
		if(A != B)
		{
			ct++;
			A++;
			if(A > n)
				A = 1;
			flag = 0;
		}
		if(A == B)
		{
			flag = 1;
			i++;
		}
//		printf("A :%d B :%d i :%d ct :%d\n",A,B,i,ct);
	}
	printf("%I64d\n",(long long )ct);
	return 0;
}


#include<stdio.h>
int main()
{
	int m,n,A=1,B,ct=0;
	scanf("%d%d",&n,&m);
	while(m--)
	{
		scanf("%d",&B);
		if(B < A)
			ct++;
		A = B;
	}
	printf("%I64d\n",(long long )ct * n + B - 1);
	return 0;
}


#include<stdio.h>
#include<stdlib.h>
int main()
{
	int m,i,n,*A,*B,ct=0,k=0;
	scanf("%d%d",&n,&m);
	A = (int *)malloc(sizeof(int)*n);
	B = (int *)malloc(sizeof(int)*m);
	for(i=0;i<n;++i)
		A[i] = i+1;
	for(i=0;i<m;++i)
		scanf("%d",&B[i]);
	for(i=1;i<n;)
	{
		if(A[i] != B[k])
		{
			ct++;
			i++;
		}
		else
		{
			ct++;
			k++;
			i++;
		}
		if(A[i-1] == B[k])
			k++;
		if(k == m)
		{
			printf("%d\n",ct);
			return 0;
		}
	}
	while(1)
	{
		for(i=0;i<n;)
		{
			if(A[i] != B[k])
			{
				ct++;
				i++;
			}
			else
			{
				k++;
				ct++;
				i++;
			}
			if(A[i-1] == B[k])
				k++;
			if(k == m)
			{
				printf("%d\n",ct);
				return 0;
			}
		}
/*			printf("Iteration :%d\n",i);
			printf("ct :%d\n",ct);*/
	}
}


#include<stdio.h>
int main()
{
    int count=0,i,a,b;
    scanf("%d%d",&a,&b);
    int c[b];
    for(i=0;i<b;i++)
        scanf("%d",&c[i]);
    count=c[0];
    for(i=1;i<b;i++)
    {
        if(c[i]<c[i-1])
            count+=a-c[i]+1;
        else if(c[i]>c[i-1])
            count=count+(c[i-1]-c[i])+1;
    }
    printf("%d\n",count);
    return 0;
}


#include<stdio.h>
int main()
{
    int count=0,i,a,b,p=0,q=1;;
    scanf("%d%d",&a,&b);
    int c[b];
    for(i=0;i<b;i++)
        scanf("%d",&c[i]);
    count=c[0]-1;
    for(i=1;i<b;i++)
    {
        if(c[i]<c[i-1]){q=0;p=0;
            count+=a-c[i]+1;}
        else if(c[i]>c[i-1]){q=0;p=0;
            count=count+(c[i]-c[i-1]);}
        else if(q==1)
            p=1;
    }
    if(p==0)
    printf("%d\n",count);
    else
    printf("0\n");
    return 0;
}


#include<stdio.h>
int main()
{
    int count=0,i,a,b,p=0,q=1;;
    scanf("%d%d",&a,&b);
    int c[b];
    for(i=0;i<b;i++)
        scanf("%d",&c[i]);
    count=c[0]-1;
    for(i=1;i<b;i++)
    {
        if(c[i]<c[i-1]){q=0;p=0;
            count+=a-c[i-1]+c[i];}
        else if(c[i]>c[i-1]){q=0;p=0;
            count=count+(c[i]-c[i-1]);}
        else if(q==1)
            p=1;
    }
    if(p==0)
    printf("%d\n",count);
    else
    printf("0\n");
    return 0;
}


#include<stdio.h>
int main()
{
    long long int count=0,i,a,b,p=0,q=1;;
    scanf("%I64d%I64d",&a,&b);
    int c[b];
    for(i=0;i<b;i++)
        scanf("%d",&c[i]);
    count=c[0]-1;
    for(i=1;i<b;i++)
    {
        if(c[i]<c[i-1]){q=0;p=0;
            count+=a-c[i-1]+c[i];}
        else if(c[i]>c[i-1]){q=0;p=0;
            count=count+(c[i]-c[i-1]);}
        else if(q==1)
            p=1;
    }
    if(p==0)
    printf("%I64d\n",count);
    else
    printf("0\n");
    return 0;
}


#include<stdio.h>
int main()
{
    int count=0,i,a,b,p=0,q=1;;
    scanf("%d%d",&a,&b);
    int c[b];
    for(i=0;i<b;i++)
        scanf("%d",&c[i]);
    count=c[0];
    for(i=1;i<b;i++)
    {
        if(c[i]<c[i-1]){q=0;p=0;
            count+=a-c[i]+1;}
        else if(c[i]>c[i-1]){q=0;p=0;
            count=count+(c[i-1]-c[i])+1;}
        else if(q==1)
            p=1;
    }
    if(p==0)
    printf("%d\n",count);
    else
    printf("0\n");
    return 0;
}


#include <stdio.h>
#include <stdlib.h>

int main()
{
  long long n,m,a0,a,cycle=0;
  do{scanf("%lld%lld",&n,&m);
  }while((2>n&&n>100000)&&(1>m&&m>100000));
  scanf("%lld",&a0);
  while(--m)
  { scanf("%lld",&a);
      if(a0>a)
      {cycle++;}
    a0=a;
  }
  printf("%lld",(n*cycle+a0-1));
    return 0;
}


#include <stdio.h>
#include <stdlib.h>

int main()
{
  int n,m,a0,a,cycle=0;
  do{scanf("%d%d",&n,&m);
  }while((2>n&&n>100000)&&(1>m&&m>100000));
  scanf("%d",&a0);
  while(--m)
  { scanf("%d",&a);
      if(a0>a)
      {cycle++;}
    a0=a;
  }
  printf("%d",(n*cycle+a0-1));
    return 0;
}


#include <stdio.h>
#include <stdlib.h>

int main()
{
  long n,m,a0,a,cycle=0;
  do{scanf("%ld%ld",&n,&m);
  }while((2>n&&n>100000)&&(1>m&&m>100000));
  scanf("%ld",&a0);
  while(--m)
  { scanf("%d",&a);
      if(a0>a)
      {cycle++;}
    a0=a;
  }
  printf("%ld",(n*cycle+a0-1));
    return 0;
}


#include <stdio.h>

int main()
{
    int i,n,m,time,temp,j;

    scanf("%d",&n);
    scanf("%d",&m);

    int ara[m];

    for(i=0; i<m; i++)
    {
        scanf("%d",&ara[i]);
    }

    time=ara[0]-1;

    for(i=0; i<m-1; i++)
    {
        if(ara[i+1]>ara[i]) time+=ara[i+1]-ara[i];

        else if(ara[i+1]<ara[i]) time+=n-ara[i]+ara[i+1];
    }

    printf("%d",time);
}


#include <stdio.h>

int main()
{
    int i,n,m;

    int temp;

    long long time;

    scanf("%d",&n);

    scanf("%d",&m);

    int ara[m];

    for(i=0; i<m; i++)
    {
        scanf("%d",&ara[i]);
    }

    time=ara[0]-1;

    for(i=0; i<m-1; i++)
    {
        if(ara[i+1]>ara[i]) time+=ara[i+1]-ara[i];

        else if(ara[i+1]<ara[i]) time+=n-ara[i]+ara[i+1];
    }

    printf("%lld",time);
}


#include <stdio.h>

int main()
{
    int i,n,m,temp,j;

    long time;

    scanf("%d",&n);
    scanf("%d",&m);

    int ara[m];

    for(i=0; i<m; i++)
    {
        scanf("%d",&ara[i]);
    }

    time=ara[0]-1;

    for(i=0; i<m-1; i++)
    {
        if(ara[i+1]>ara[i]) time+=ara[i+1]-ara[i];

        else if(ara[i+1]<ara[i]) time+=n-ara[i]+ara[i+1];
    }

    printf("%ld",time);
}


#include <stdio.h>

int main()
{
    int i,n,m,time,temp,j;

    scanf("%d",&n);
    scanf("%d",&m);

    int ara[m];

    for(i=0; i<m; i++)
    {
        scanf("%d",&ara[i]);
    }

    time=ara[0]-1;

    for(i=0; i<m-1; i++)
    {
        if(ara[i+1]>ara[i]) time+=ara[i+1]-ara[i];

        else if(ara[i+1]<ara[i]) time+=n+ara[i]-ara[i+1];
    }

    printf("%d",time);
}


#include <stdio.h>

int main()
{
    int i,n,m,time,temp,j;

    scanf("%d",&n);
    scanf("%d",&m);

    int ara[m];

    for(i=0; i<m; i++)
    {
        scanf("%d",&ara[i]);
    }

    time=ara[0]-1;

    printf("%d\n",time);

    for(i=0; i<m-1; i++)
    {
        if(ara[i+1]>ara[i]) time+=ara[i+1]-ara[i];

        else if(ara[i+1]<ara[i]) time+=n-ara[i]+ara[i+1];

        printf("\n%d\n",time);
    }

    printf("%d",time);
}


#include<stdio.h>

int main()
{
    int n,m,i,count=0;
    scanf("%d %d",&n,&m);
    int a[m];
    for(i=0; i<m; i++)
    {
        scanf("%d",&a[i]);
    }
    for(i=0; i<(m-2); i++)
    {
        if(a[i]>a[i+1])
        {
            count=count+n;
        }
    }
    count =count+a[m-1];
    count=count-1;
    printf("%d",count);
    return 0;
}


#include<stdio.h>

int main()
{
    double n,m,count=0;
    int i;
    scanf("%lf %lf",&n,&m);
    double a[m];
    for(i=0; i<m; i++)
    {
        scanf("%lf",&a[i]);
    }
    for(i=0; i<(m-2); i++)
    {
        if(a[i]>a[i+1])
        {
            count=count+n;
        }
    }
    count=count+a[m-1]-1;
    printf("%0.0lf",count);
    return 0;
}


#include<stdio.h>

int main()
{
    double n,m,count=0;
    int i;
    scanf("%lf %lf",&n,&m);
    double a[(long int)m];
    for(i=0; i<m; i++)
    {
        scanf("%lf",&a[i]);
    }
    for(i=0; i<(m-2); i++)
    {
        if(a[i]>a[i+1])
        {
            count=count+n;
        }
    }
    count=count+a[(long int)m-1]-1;
    printf("%0.0lf",count);
    return 0;
}


#include<stdio.h>

int main()
{
    double n,m,count=0;
    int i;
    scanf("%lf %lf",&n,&m);
    double a[(long int)m];
    for(i=0; i<(long int)m; i++)
    {
        scanf("%lf",&a[i]);
    }
    for(i=0; i<((long int)m-1); i++)
    {
        if(a[i]>a[i+1])
        {
            count=count+n;
        }
    }
    count=count+a[(long int)m-1]-1;
    printf("%0.0lf",count);
    return 0;
}


//https://codeforces.com/contest/1143/problem/A
#include<bits/stdc++.h>
using namespace std;
#define loop(i,a,b) for(int i=a;i<b;++i)
bool ispresent(short,short [],long,long);
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    long n,k=0;
    cin>>n;
    short door[n];
    loop(i,0,n)
        cin>>door[i];
    loop(i,0,n){
        k++;
        if(!ispresent(door[i],door,i,n))
            break;
    }
    cout<<k;
    return 0;
}
bool ispresent(short x, short a[], long cur,long size){
    loop(i,cur+1,size){
        if(a[i]==x){
            return true;
        }
    }
    return false;
}


//https://codeforces.com/contest/1143/problem/A
#include<bits/stdc++.h>
using namespace std;
#define loop(i,a,b) for(int i=a;i<b;++i)
bool ispresent(short,vector<short>,long,long);
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    long n,k=0;
    cin>>n;
    vector <short> door(n);
    loop(i,0,n)
        cin>>door[i];
    loop(i,0,n){
        k++;
        if(!ispresent(door[i],door,i,n))
            break;
    }
    cout<<k;
    return 0;
}
bool ispresent(short x, vector<short> a, long cur,long size){
    sort(a.begin()+(cur+1),a.end());
    long int low=cur+1,high=size-1;
    while(low<=high){
        long mid=(low+high)/2;
        if(x==a[mid])
            return true;
        else if(x>a[mid])
            low=mid+1;
        else
            high=mid-1;
    }
    return false;
}


//https://codeforces.com/contest/1143/problem/A
#include<bits/stdc++.h>
using namespace std;
#define loop(i,a,b) for(int i=a;i<b;++i)
bool ispresent(short,vector<short>,long,long);
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    long n,k=0;
    cin>>n;
    vector <short> door(n);
    loop(i,0,n)
        cin>>door[i];
    loop(i,0,n){
        k++;
        if(!ispresent(door[i],door,i,n))
            break;
    }
    cout<<k;
    return 0;
}
bool ispresent(short x, vector<short> a, long cur,long size){
    loop(i,cur+1,size){
        if(a[i]==x){
            return true;
        }
    }
    return false;
}


//https://codeforces.com/contest/1143/problem/A
#include<bits/stdc++.h>
using namespace std;
#define loop(i,a,b) for(int i=a;i<b;++i)
bool ispresent(short,vector<short>,long,long);
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    long n,k;
    cin>>n;
    vector <short> door(n);
    loop(i,0,n)
        cin>>door[i];
    loop(i,0,n){
        k++;
        if(!ispresent(door[i],door,i,n))
            break;
    }
    cout<<k;
    return 0;
}
bool ispresent(short x, vector<short> a, long cur,long size){
    sort(a.begin()+(cur+1),a.end());
    long int low=cur+1,high=size-1;
    while(low<=high){
        long mid=(low+high)/2;
        if(x==a[mid])
            return true;
        else if(x>a[mid])
            low=mid+1;
        else
            high=mid-1;
    }
    return false;
}


#include<bits/stdc++.h>
#define ll long long
using  namespace std;
ll cn[1000000];
int main()
{
    ll n,m,i,j,k,l,r,e;
    cin>>n;
    ll cnt=0;
    ll arr[n];
    for(i=0; i<n; i++)cin>>arr[i],cn[arr[i]]++;
    ll ans=0,mnt=0;
    for(i=0; i<n; i++)
    {cn[arr[i]]--;
    if(cn[arr[i]]==0)
    {
        cout<<i+1<<endl;
        return 0;
    }
    }
    // cout<<ans<<endl;
    return 0;
}


#include<bits/stdc++.h>
#define ll long long
using  namespace std;
int main()
{
    ll n,m,i,j,k,l,r,e;
    cin>>n;
    ll cnt=0;
    ll arr[n];
    for(i=0; i<n; i++)cin>>arr[i];
    ll ans=0,mnt=0;
    for(i=0; i<n; i++)
    {
        if(arr[i]==1)
        {
            cnt++;
        }
        else
            mnt++;
        if(cnt!=0 && mnt !=0 && cnt!=mnt)
        {
            cout<<i+1<<endl;
            return 0;
        }
    }
    // cout<<ans<<endl;
    return 0;
}


#include<bits/stdc++.h>
#define ll long long
using  namespace std;
int main()
{
    ll n,m,i,j,k,l,r,e;
    cin>>n;
    ll cnt=1;
    ll arr[n];
    for(i=0;i<n;i++)cin>>arr[i];
    ll ans=0;
    for(i=0;i<n;i++)
    {
        if(arr[i]==1)
        {
            ans=max(ans,cnt);
            cnt=1;
        }
        else
            cnt++;
    }
    cout<<ans<<endl;
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    long long a[190000],s=0,p,q,i,n;
    cin>>n;
    for(i=0;i<n;i++)
    {
        cin>>a[i];
    }
     for(i=1;i<=n;i++)
     {
         if(a[i]==0)
         {
             p=i;
         }
         else
         {
             q=i;
         }
     }
    cout<<min(p,q)<<endl;

}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    long long a[190000],s=0,p,q,i,n;
    cin>>n;
    for(i=1;i<=n;i++)
    {
        cin>>a[i];
    }
     for(i=1;i<=n;i++)
     {
         if(a[i]==0)
         {
             p=i;
         }
         else
         {
             q=i;
         }
     }
    cout<<min(p,q)<<endl;

}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    long long a[19000099],s=0,p,q,i,n;
    cin>>n;
    for(i=1;i<=n;i++)
    {
        cin>>a[i];
    }
     for(i=1;i<=n;i++)
     {
         if(a[i]==0)
         {
             p=i;
         }
         else
         {
             q=i;
         }
     }
    cout<<min(p,q)<<endl;

}


#define ll long long int
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <cmath>
#include <set>
using namespace std;
const ll y = 1000;
const ll INF = y*y*y*y*y*y;
int main() {
	int n;
	cin >> n;
	vector <int> a(n);
	int n0=0, n1=0;
	for (int i = 0; i < n; i++) {
		cin >> a[i];
		if (a[i] == 0) n0 = i;
		else n1 = i;
	}
	cout << min(n1, n2);
}


#define ll long long int
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <cmath>
#include <set>
using namespace std;
const ll y = 1000;
const ll INF = y*y*y*y*y*y;
int main() {
	int n;
	cin >> n;
	vector <int> a(n);
	int n0=0, n1=0;
	for (int i = 0; i < n; i++) {
		cin >> a[i];
		if (a[i] == 0) n0 = i;
		else n1 = i;
	}
	cout << min(n1, n0);
}


#define ll long long int
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <cmath>
#include <set>
using namespace std;
const ll y = 1000;
const ll INF = y*y*y*y*y*y;
int main() {
	int n;
	cin >> n;
	vector <int> a(n);
	int n0=0, n1=0;
	for (int i = 0; i < n; i++) {
		cin >> a[i];
		if (a[i] == 0) n0 = i;
		else n1 = i;
	}
	cout << min(n1, n0)+1;
}


#include <iostream>
using namespace std;
int main()
{
    int n;
    cin >> n;
    int a=0;
    int A[n];
    for(int i=0;i<n;i++)
    {
        cin>>A[i];
    }
    for(int i=n-2;i>=0;i--)
    {
        if(A[i]==A[n-1]) a++;
    }
    if(a==n-1)
    {
        cout <<n<<endl;
    }
    else
    {
        if(n==2&&A[0]!=A[1])
        {
            cout <<1<<endl;
        }
        else
        {
            for(int i=n-2;i>0;i--)
            {
                if(A[i]!=A[n-1])
                {
                    cout <<i+1<<endl;
                    break;
                }
            }
        }
    }
}


#include <iostream>
using namespace std;
int main()
{
    int n;
    cin >> n;
    int A[n];
    for(int i=0;i<n;i++)
    {
        cin>>A[i];
    }
    for(int i=n-2;i>0;i--)
    {
        if(A[i]!=A[n-1])
        {
            cout <<i+1<<endl;
            break;
        }
    }
}


#include <iostream>
using namespace std;
int main()
{
    int n;
    cin >> n;
    int A[n];
    for(int i=0;i<n;i++)
    {
        cin>>A[i];
    }
    for(int i=n-2;i>0;i--)
    {
        if(A[i]!=A[n-1])
        {
			cout <<i+1<<endl;
        	return 0;
        }
    }
    cout <<n<<endl;
}


#include <iostream>
using namespace std;
int main()
{
    int n;
    cin >> n;
    int a=0;
    int A[n];
    for(int i=0;i<n;i++)
    {
        cin>>A[i];
    }
    int j=n-2;
    while(A[j]==A[n-1]) j--;
    cout<<j+1<<endl;
}


#include <iostream>
using namespace std;
int main()
{
    int n;
    cin >> n;
    int A[n];
    for(int i=0;i<n;i++)
    {
        cin>>A[i];
    }
    for(int i=n-2;i>0;i--)
    {
        if(A[i]!=A[n-1])
        {
			cout <<i+1<<endl;
        	break;
        }
    }
    cout <<n<<endl;
}


#include <iostream>
int main()
{
	int total;
	char doors[1000];
	int count = 0;
	int i = 0;
	std::cin >> total;
	do
	{
		std::cin >> doors[i];
		if (i > 0)
		{
			if (doors[i] != doors[i - 1])
			{
				count = i;
			}
		}
		i++;
	} while (i < total);
	std::cout << count;
}


#include <iostream>
int main()
{
	int total;
	int doors[1000];
	std::cin >> total;
	for (int i = 0; i < total; i++)
	{
		std::cin >> doors[i];
	}
	for (int i = total - 2; i >= 0; i--)
	{
		if (doors[i] != doors[total-1])
		{
			std::cout << i + 1;
			return 0;
		}
	}
}


#include <iostream>
int main()
{
	int total;
	char doors[200000];
	int count = 0;
	int i = 0;
	std::cin >> total;
	do
	{
		std::cin >> doors[i];
		if (i > 0)
		{
			if (doors[i] != doors[i - 1])
			{
				count = i;
			}
		}
		i++;
	} while (i < total);
	std::cout << count;
}


#include<bits/stdc++.h>

using namespace std;

int a[200010];

int main(){

    int n;
    int n0 = 0,int n1 = 0;
    for(int i  = 0;i<n;i++){
        int inp;
        cin>>inp;
        if(inp == 0) n0 = i+1;
        if(inp == 1) n1 = i+1;
    }
    cout<<min(n0,n1);
    return 0;
}


#include<bits/stdc++.h>

using namespace std;

int a[200010];

int main(){

    int n;
    int n0 = 0, n1 = 0;
    for(int i  = 0;i<n;i++){
        int inp;
        cin>>inp;
        if(inp == 0) n0 = i+1;
        if(inp == 1) n1 = i+1;
    }
    cout<<min(n0,n1);
}


#include<bits/stdc++.h>

using namespace std;

int a[200010];

int main(){

    int n;
    cin>>n;
    int n0 = 0, n1 = 0;
    for(int i  = 0;i<n;i++){
        int inp;
        cin>>inp;
        if(inp == 0) n0 = i+1;
        if(inp == 1) n1 = i+1;
    }
    cout<<min(n0,n1);
}


#include <bits/stdc++.h>
using namespace std;
int main()
{
    unsigned int i,n,a,l=0,r=0,ml,mr,m;
    bool kt=true;
    cin>>n;
    mr=n/2+1;
    if((n%2)==0)ml=n/2;
        else ml=n/2+1;
    m=ml;
    for(i=1;i<=n;i++)
    {
        cin>>a;
        if((a==1)and(i<=ml)) l++;
        if((a==1)and(i>=mr)) r++;
    }
    if (l>=r) cout<<m-l;
    else cout<<m-r;
}


#include <bits/stdc++.h>
using namespace std;
int main()
{
    unsigned int i,n,a;
    bool kt=true;
    cin>>n;
    for(i=0;i<n;i++)
    {
        cin>>a;
        if((a==1)and(i==(n/2))and((i%2)==0)) {cout<<i+1;kt=false;}
    }
    if (kt==true) cout<<n-2;
}


#include <bits/stdc++.h>
using namespace std;
int main()
{
    unsigned int i,n,a;
    bool kt=true;
    cin>>n;
    for(i=0;i<n;i++)
    {
        cin>>a;
        if((a==1)and(i==(n/2))and((i%2)==0)) {cout<<i+1;kt=false;}
    }
    if (kt==true)
    {
        if ((n%2)==0)cout<<n/2;
        else cout<<(n/2)+1;
    }
}


#include <bits/stdc++.h>
using namespace std;
int main()
{
    //freopen("test.inp","r",stdin);
    int n,i,s=0,b=0;bool j;
    cin>>n;
    for(i=1;i<=n;i++)
    {
        cin>>j;
        if (j==0) s=i;
        else b=i;
    }
    if (s<b) cout<<s;
    else cout<<b;
}


#include <bits/stdc++.h>
using namespace std;
int main()
{
    unsigned int i,n,a,l=0,r=0,ml,mr,m;
    bool kt=true;
    cin>>n;
    mr=n/2+1;
    if((n%2)==0)ml=n/2;
        else ml=n/2+1;
    m=ml;
    for(i=1;i<=n;i++)
    {
        cin>>a;
        if((a==1)and(i<=ml)) l++;
        if((a==1)and(i>=mr)) r++;
    }
    if (l>=r) cout<<m-l+1;
    else cout<<m-r+1;
}


#include <bits/stdc++.h>

using namespace std;

int d[200010];

int main(){
    int n,j;
    cin >> n;
    for(int i=1;i<=n;i++){
        int a;
        cin >> d[i];
    }
    j = n;
    while(j){
        if(d[j]!=d[n]){
            cout << j << endl;
        }
        --j;
    }
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

int d[200010];

int main(){
    int n,j;
    cin >> n;
    for(int i=1;i<=n;i++){
        int a;
        cin >> d[i];
    }
    j = n;
    while(j){
        if(d[j]!=d[n]){
            cout << j << endl;
            break;
        }
        --j;

    }
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

int main(){
    int n,z,u,a;
    cin >> n;
    for(int i=1;i<=n;i++){cin >> a;if(a)u=i;else z=i;}
    cout << min(u,z) << endl;
    return 0;
}


#include<iostream>
using namespace std;
int main(){
    int n, i;
    cin>>n;
    int a[n];
    for(int i = 0; i< n; i++){
        cin>>a[i];
    }
    for(i = n-2; i >= 0; i--){
        if(a[n] != a[n-1]){
            break;
        }
    }
    cout<<i;
}


#include<iostream>
using namespace std;
int main(){
    int n, i;
    cin>>n;
    int a[n];
    for(int i = 0; i< n; i++){
        cin>>a[i];
    }
    for(i = n-2; i >= 0; i--){
        if(a[i] != a[i-1]){
            break;
        }
    }
    cout<<i;
}


#include<iostream>
using namespace std;
int main(){
    int n, i;
    cin>>n;
    int a[n], left = 0, right = 0;
    for(int i = 0; i < n; i++){
        cin>>a[i];
        if(a[i] == 0){
            right = i;
        }
        else{
            left = i;
        }
    }
    if(left>right){
        cout<<right+1;
    }
    else{
        cout<<left+1;
    }
}


#include<bits/stdc++.h>
#define TP int
using namespace std;
inline TP read(){
    char c=getchar();
    TP x=0;
    bool f=0;
    while(!isdigit(c))f^=!(c^45),c=getchar();
    while(isdigit(c))x=(x<<1)+(x<<3)+(c^48),c=getchar();
    if(f)x=-x;return x;
}
inline double readdouble(){
    char c=getchar();
    double x=0;
    bool f=0;
    while(!isdigit(c))f^=!(c^45),c=getchar();
    while(isdigit(c))x=x*10+(c^48),c=getchar();
    if(!(c^46)){
        double t=1;c=getchar();
        while(isdigit(c))t/=10,x+=t*(c^48),c=getchar();
    }if(f)x=-x;return x;
}
inline bool blank(char c){return !(c&&c^9&&c^10&&c^13&&c^32);}
inline void readstr(char *s){
    char c=getchar();
    while(blank(c))c=getchar();
    while(!blank(c))*s++=c,c=getchar();*s=0;
}
inline bool isendl(char c){return !(c&&c^10&&c^13);}
inline void getstr(char *s){
    char c=getchar();
    while(isendl(c))c=getchar();
    while(!isendl(c))*s++=c,c=getchar();*s=0;
}
int n=read(),i,qw1,qw2,k;
int main(){
	for(int i=0;i<n;i++){
		k=read();
		if(k==0){
			qw1=i;
		}
		else{
			qw2=i;
		}
	}
	cout<<min(qw1,qw2);
    return 0;
}


#include <stdio.h>
#define ri register int
int number[200010];
int min(int a, int b) {
    return a > b ? b : a;
}

int main()
{
    int n;
    scanf("%d", &n);
    for (ri i = 1; i <= n; ++i)
        scanf("%d", &number[i]);
    int right = n, left = n;
    while (number[right] == 1)
        right--;
    while (number[left] == 0)
        left--;
    printf("%d\n", min(left, right));
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
int a[2222322];
int main(){
	int n;
	int s=0,s1=0,s2=0;
	for(int i=1;i<=n;i++){
		cin>>a[i];
		if(a[i]==1)s2++;
		else s1++;
	}
	for(int i=1;i<=n;i++){
		if(a[i]==1)s2--;
		else s1--;
		if(s1==0||s2==0){
			cout<<i;
			return 0;
		}
	}
	return 0;
}


#include <iostream>
using namespace std;

int main()
{
	int n,i,cnt=0,a1=0,b=0;
	cin>>n;
	int a[n];
	for(i=0;i<n;i++){
		cin>>a[i];
		if(a[i]==0){
			cnt++;
		}
	}
	int cnt1=n-cnt;
	for(i=0;i<n;i++){
		if(a[i]==0){
			a1++;
		}else{
			b++;
		}
		if(a1==cnt||b==cnt1){
			break;
		}
	}
	cout<<i+1;
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
	int a[200001],n;
	scanf("%d",&n);
	for(int i=1;i<=n;++i)
	{
		cin>>a[i];
	}
	int x=0,y=0;
	for(int i=n;i>=1;i--)
	{
		if(a[i])
		{
			x++;
		}
		else
		{
			++y;
		}
		if(x&&y)
		{
			cout<<i<<endl;
			return 0;
		}
	}
	return 0;
}


#include <iostream>
using namespace std;
int a[100001];
int l=0,r=0;
int main(){
	int i,j,k,n;
	cin>>n;
	for(i=1;i<=n;i++)cin>>a[i];
	for(i=n;i>=2;i--)
	if(l==0||r==0){
		if(a[i]==0)l=i;
		else r=i;
	}
	else break;
	cout<<min(l,r)<<endl;
	return 0;
}


#include<cstdio>
using namespace std;

const int maxn=2e5+5;
int n,lastl,lastr,door;

int main(){
	scanf("%d",&n);
	for(int i=0;i<n;i++){
		scanf("%d",&door);
		if(door) lastr=i+1;
		else lastl=i+1;
	}
	if(lastl<lastr) printf("%d",lastl);
	else printf("%d",lastr);
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
int n,i,max1,max2,k;
int main(){
    cin>>n;
    for(int i=1;i<=n;i++){
        cin>>k;
        if(k==0) max1=i;
            else max2=i;
    }
    cout<<min(max1,max2)<<endl;
    return 0;
}


#include <bits/stdc++.h>

#define mkp make_pair
#define pb push_back
#define all(x) x.bg,x.ed
#define newline puts("")
#define rep(i,n) for(int i=1;i<=n;++i)
#define rrep(i,n) for(int i=0;i<n;++i)

using namespace std;
typedef long long ll;
typedef pair<ll,ll> pii;
const int maxn = 1e6+10;
const int inf = 0x7f7f7f7f;
const int Mod = 1e9+7;
const double eps = 1e-7;
int a[maxn];
int n;

int main(){
    cin>>n;
    for (int i=1;i<=n;i++) scanf("%d",&a[i]);
    int ans1=0,ans2=0;
    for (int i=1;i<=n;i++){
        if(a[i]==0) {
            ans1=max(ans1,i);
        }
        else if(a[i]==1){
            ans2=max(ans2,i);
        }
    }
    if(ans1==0) cout<<ans2<<endl;
    else if(ans2==0) cout<<ans1<<endl;
    else cout<<min(ans1,ans2)<<endl;
    return 0;
}


#include<iostream>
using namespace std;
int main()
{
	int l=0,m=0,i,j,n,x=0,y=0;
int long long a[90000];
	cin>>n;
	for(i=1;i<=n;i++)
	{
		cin>>a[i];
		if(a[i]==0)
			l++;
		else
			m++;
	}
	for(i=1;i<=n;i++)
	{
		if(a[i]==0)
			{
				x++;
				if(x==l)
				{
					cout<<i<<endl;
					return 0;
				}
			}
		else
			{
				y++;
				if(y==m)
				{
					cout<<i<<endl;
					return 0;
				}

			}
	}
}


#include<iostream>
using namespace std;
int main()
{
	int l=0,m=0,i,j,n,x=0,y=0,a[1000];
	cin>>n;
	for(i=1;i<=n;i++)
	{
		cin>>a[i];
		if(a[i]==0)
			l++;
		else
			m++;
	}
	for(i=1;i<=n;i++)
	{
		if(a[i]==0)
			{
				x++;
				if(x==l)
				{
					cout<<i<<endl;
					return 0;
				}
			}
		else
			{
				y++;
				if(y==m)
				{
					cout<<i<<endl;
					return 0;
				}

			}
	}
}


#include<iostream>
using namespace std;
int main()
{
	int l=0,m=0,i,j,n,x=0,y=0;
int long long a[1000000];
	cin>>n;
	for(i=1;i<=n;i++)
	{
		cin>>a[i];
		if(a[i]==0)
			l++;
		else
			m++;
	}
	for(i=1;i<=n;i++)
	{
		if(a[i]==0)
			{
				x++;
				if(x==l)
				{
					cout<<i<<endl;
					return 0;
				}
			}
		else
			{
				y++;
				if(y==m)
				{
					cout<<i<<endl;
					return 0;
				}

			}
	}
}


#include<iostream>
using namespace std;
int main()
{
	int l=0,m=0,i,j,n,x=0,y=0,a[50];
	cin>>n;
	for(i=1;i<=n;i++)
	{
		cin>>a[i];
		if(a[i]==0)
			l++;
		else
			m++;
	}
	for(i=1;i<=n;i++)
	{
		if(a[i]==0)
			{
				x++;
				if(x==l)
				{
					cout<<i<<endl;
					return 0;
				}
			}
		else
			{
				y++;
				if(y==m)
				{
					cout<<i<<endl;
					return 0;
				}

			}
	}
}


#include<bits/stdc++.h>

using namespace std;

//Shortcut
#define lb long double
#define ll long long
#define pb push_back
#define pf push_front
#define mp make_pair
#define X first
#define Y second
#define sz size() - 1
#define all(a) (a).begin() , (a).end()
#define write(a) {cout << a; return;}
#define isvowel(a) (a == 'e' || a == 'u' || a == 'o' || a == 'a' || a == 'i')
#define ft(i , a , b) for (ll i = (ll)a ; i <= (ll)b ; i++)
#define fd(i , a , b) for (ll i = (ll)a ; i >= (ll)b ; i--)
#define lt(i , a , b , c) for (ll i = (ll)a ; i <= (ll)b ; i += (ll)c)
#define ld(i , a , b , c) for (ll i = (ll)a ; i >= (ll)b ; i -= (ll)c)
#define pll pair <ll , ll>
#define pls pair <ll , string>
#define vtl vector <ll>
#define vts vector <string>
#define vtp vector <pll>
#define dql deque <ll>
#define mll map <ll , ll>
#define prio priority_queue<pll , vector<pll > , greater<pll> >

//Variable
const ll mxN = 1e5 + 5;
const ll base = 311;
const ll oo = 1e15;
const ll MOD = 1e9 + 7;
const lb EPS = 1e-10;
const ll bignumbase = 1000000000;
const ll bignumdigits = 9;
const ll d4i[4] = {-1 , 0 , 1 , 0} , d4j[4] = {0 , 1 , 0 , -1};
const ll d8i[8] = {-1 , -1 , 0 , 1 , 1 , 1 , 0 , -1} , d8j[8] = {0 , 1 , 1 , 1 , 0 , -1 , -1 , -1};

ll TestCase;
ll n;
ll a[mxN] , trai[mxN] , phai[mxN];

void Solve() {
    cin >> n;
    ft(i , 1 , n) cin >> a[i];
    fd(i , n , 1) trai[i] = trai[i + 1] + (a[i] == 0) , phai[i] = phai[i + 1] + (a[i] == 1);
    ft(i , 1 , n) {
        if (phai[i + 1] == 0 || trai[i + 1] == 0) {
            cout << i;
            return;
        }
    }
}

int main() {
    ios_base::sync_with_stdio(NULL);
    cin.tie(NULL);
    cout.tie(NULL);
    //freopen(".inp" , "r" , stdin);
    //freopen(".out" , "w" , stdout);
    //cin >> TestCase;
    TestCase = 1;
    while(TestCase--)
        Solve();
    return 0;
}


#include<bits/stdc++.h>

using namespace std;

//Shortcut
#define lb long double
#define ll long long
#define pb push_back
#define pf push_front
#define mp make_pair
#define X first
#define Y second
#define sz size() - 1
#define all(a) (a).begin() , (a).end()
#define write(a) {cout << a; return;}
#define isvowel(a) (a == 'e' || a == 'u' || a == 'o' || a == 'a' || a == 'i')
#define ft(i , a , b) for (ll i = (ll)a ; i <= (ll)b ; i++)
#define fd(i , a , b) for (ll i = (ll)a ; i >= (ll)b ; i--)
#define lt(i , a , b , c) for (ll i = (ll)a ; i <= (ll)b ; i += (ll)c)
#define ld(i , a , b , c) for (ll i = (ll)a ; i >= (ll)b ; i -= (ll)c)
#define pll pair <ll , ll>
#define pls pair <ll , string>
#define vtl vector <ll>
#define vts vector <string>
#define vtp vector <pll>
#define dql deque <ll>
#define mll map <ll , ll>
#define prio priority_queue<pll , vector<pll > , greater<pll> >

//Variable
const ll mxN = 2e5 + 5;
const ll base = 311;
const ll oo = 1e15;
const ll MOD = 1e9 + 7;
const lb EPS = 1e-10;
const ll bignumbase = 1000000000;
const ll bignumdigits = 9;
const ll d4i[4] = {-1 , 0 , 1 , 0} , d4j[4] = {0 , 1 , 0 , -1};
const ll d8i[8] = {-1 , -1 , 0 , 1 , 1 , 1 , 0 , -1} , d8j[8] = {0 , 1 , 1 , 1 , 0 , -1 , -1 , -1};

ll TestCase;
ll n;
ll a[mxN] , trai[mxN] , phai[mxN];

void Solve() {
    cin >> n;
    ft(i , 1 , n) cin >> a[i];
    fd(i , n , 1) trai[i] = trai[i + 1] + (a[i] == 0) , phai[i] = phai[i + 1] + (a[i] == 1);
    ft(i , 1 , n) {
        if (phai[i + 1] == 0 || trai[i + 1] == 0) {
            cout << i;
            return;
        }
    }
}

int main() {
    ios_base::sync_with_stdio(NULL);
    cin.tie(NULL);
    cout.tie(NULL);
    //freopen(".inp" , "r" , stdin);
    //freopen(".out" , "w" , stdout);
    //cin >> TestCase;
    TestCase = 1;
    while(TestCase--)
        Solve();
    return 0;
}


#include <bits/stdc++.h>
using namespace std;

int main()
{
	vector<int> V;
    int x, y, c0= 0, c1= 0;
    cin >> x;
    for(int i=0; i<x; i++)
	{
		cin >> y;
		V.push_back(y);
		if(y==0)
		{
			c0++;
		}
		else
		{
			c1++;
		}
	}
	int cc0  = c0, cc1 = c1;
	for(int i=0; i<x; i++)
	{
		if(V[i]==0)
		{
			c0--;
		}
		else
		{
			c1--;
		}
		if((c0==0 and c1!=cc1) or (c1==0 and c0!=cc0))
		{
			cout << i+1 << endl;
			break;
		}
	}
}


#include <bits/stdc++.h>
using namespace std;

int main()
{
	vector<int> V;
    int x, y, c0= 0, c1= 0;
    cin >> x;
    for(int i=0; i<x; i++)
	{
		cin >> y;
		V.push_back(y);
		if(y==0)
		{
			c0++;
		}
		else
		{
			c1++;
		}
	}
	int cc0  = c0, cc1 = c1;
	for(int i=0; i<x; i++)
	{
		if(V[i]==0)
		{
			c0--;
		}
		else
		{
			c1--;
		}
		if(c0==0 or c1==0 and c0!=cc0 and c1!=cc1)
		{
			cout << i+1 << endl;
			break;
		}
	}
}


#include <bits/stdc++.h>
using namespace std;

int main()
{
	vector<int> V;
    int x, y, c0= 0, c1= 0;
    cin >> x;
    for(int i=0; i<x; i++)
	{
		cin >> y;
		V.push_back(y);
		if(y==0)
		{
			c0++;
		}
		else
		{
			c1++;
		}
	}
	int cc0  = c0, cc1 = c1;
	for(int i=0; i<x; i++)
	{
		if(V[i]==0)
		{
			c0--;
		}
		else
		{
			c1--;
		}
		if(c0==0 or c1==0)
		{
			cout << i+1 << endl;
			break;
		}
	}
}


#include <bits/stdc++.h>
using namespace std;

int wire[200005], one, zero, n;

int main(){
	cin >> n;
	for(int i = 0 ; i < n ; i++){
		cin >> wire[i];
		if(wire[i] == 1) one++;
		else zero++;
	}
	for(int i = 0 ; i < n ; i++){
		if(wire[i] == 1) one--;
		else zero--;
		if(!one || !zero) return cout << i + 1, 0;
	}

}


#include <bits/stdc++.h>
using namespace std;

int wire[105], one, zero, n;

int main(){
	cin >> n;
	for(int i = 0 ; i < n ; i++){
		cin >> wire[i];
		if(wire[i] == 1) one++;
		else zero++;
	}
	for(int i = 0 ; i < n ; i++){
		if(wire[i] == 1) one--;
		else zero--;
		if(!one || !zero) return cout << i + 1, 0;
	}

}


#include<bits/stdc++.h>
using namespace std;
template <class T> inline void read(T&x){
	bool f;char ch=getchar();
	for(f=false;!isdigit(ch);ch=getchar())if(ch=='-')f=true;
	for(x=0;isdigit(ch);x=(x<<1)+(x<<3)+(ch^48),ch=getchar());
	x*=f==1?-1:1;
}
int main(){
	int n;
    cin>>n;
    int ans1=0,ans2=0;
    for(int i=0;i<n;i++) {
        int a;
        cin>>a;
        if(a==0) ans1 = i;
        else ans2 = i;
    }
    cout<<min(ans1,ans2)+1<<endl;
	return 0;
}


#include <algorithm>
#include <iostream>
int n, arr[200005];
int main()
{
	int x = 0, y = 0;
	scanf("%d", &n);
	for (int i = 1; i <= n; i++)
		scanf("%d", arr + i);
	for (int i = n; i; i--)
	{
		if (arr[i]) x++;
		else y++;
		if (x & y)
		{
			printf("%d\n", i); break;
		}
	}
	return 0;
}


#include <iostream>
using namespace std;
int a[200001];
int l=0,r=0;
int main(){
	int i,j,k,n;
	cin>>n;
	for(i=1;i<=n;i++)cin>>a[i];
	for(i=n;i>=1;i--)
	if(l==0||r==0){
		if(l==0&&a[i]==0)l=i;
		if(r==0&&a[i]==1)r=i;
	}
	else break;
	cout<<min(l,r)<<endl;
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
int n,max1,max2,k;
int main(){
    cin>>n;
    for(int i=1;i<=n;i++){
		cin>>k;
      	if(k==0) max1=i;
      	else max2=i;
    }
    cout<<min(max1,max2)<<endl;
}


#include<stdio.h>
using namespace std;
int main(){
	int n,i,k,ans0=0,ans1=0;
    scanf("%d",&n);
    for(i=1;i<=n;i++){
        scanf("%d",&k);
        if(k)ans1=i;
        else ans0=i;
    }
    if(ans0<ans1)printf("%d",ans0);
    else printf("%d",ans1);
    return 0;
}


#include<bits/stdc++.h>
using namespace std;

#define LL long long
#define MAXN 200005

LL n,m;
int a[MAXN];

void rd() {
    cin >> n;
    for(int i = 1; i <= n; i ++)
        cin >> a[i];
}
//QAQ
signed main()
{
    rd();
    int k = n;
    while(a[k]  == a[n] && k > 1) k--;
        cout<<k;
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
int x,y,a[200005],n;
int main(void)
{
    cin>>n;
    for(int i=1;i<=n;++i)cin>>a[i];
    for(int i=n;i>=1;i--)
    {
        if(a[i])x++;
        else ++y;
        if(x&&y)
        {
            cout<<i<<endl;
            return 0;
        }
    }
}


/*
 This C++ Source is
 writen by syksykCCC
 (2019)
*/

#include<cstdio>
#include<climits>
#include<cctype>
#include<cstring>
#include<cmath>
#include<string>
#include<iostream>
#include<algorithm>
#include<cstdlib>
#include<set>
#include<map>
#include<queue>
#include<stack>
#include<vector>

#define QUICK_IOS ios::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL)
#define FILEIO(s) freopen((s)".in","r",stdin),freopen((s)".out","w",stdout)
#define DEBUG() freopen("in.txt","r",stdin)

#define REP(i,x,y) for(int i=x;i<=y;i++)
#define PER(i,x,y) for(int i=x;i>=y;i--)

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

template <typename T> inline void read(T &val)
{
	val = 0;
	int f = 1 ;
	char c = getchar();
	while (! isdigit(c))
	{
		if(c == '-') f = -1;
		c = getchar();
	}
	while (isdigit(c))
	{
		val = (val << 3) + (val << 1) + (c ^ 48);
		c = getchar();
	}
	val *= f;
}

int n, a[200005];

int main()
{
	read(n);
	REP(i, 1, n)
	{
		read(a[i]);
	}
	int l1 = -1, l0 = -1;
	for(int i = n; i >= 1; i --)
	{
		if(a[i] == 1)
		{
			if(l1 == -1) l1 = i;
		}
		else
		{
			if(l0 == -1) l0 = i;
		}
	}
	cout << min(l0, l1) << endl;
	return 0;
}