#include #include #define ENDD '\0' #define KIGY '\n' #define TRUE 0 #define FALSE 1 int main() { int ch; char buff[100000+1]; int buffi; int N; int jen[100000+1]; buffi = 0; while( (ch=getc(stdin)) != KIGY) { buff[buffi++] = ch; } buff[buffi] = ENDD; N = atoi(buff); buffi=0; int count = 1; while( (ch=getc(stdin)) != EOF) { if( ch==' ' || ch==KIGY ) { buff[buffi] = ENDD; jen[atoi(buff)] = count++; buffi = 0; } else { buff[buffi++] = ch; } } count = 0; for( int i = N; i >=2; i-- ) { if( jen[i] > jen[i-1] ) { continue; } count++; jen[i-1] = 1; for( int j = 1; j <= i-2; j++ ) { jen[j]--; } } /* search max */ printf("%d\n", count ); return 0; }