#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++; for( int j = 1; j <= N; j++ ) { if( jen[i-1] > jen[j] ) { jen[j]++; } } jen[i-1] = 1; } /* search max */ printf("%d\n", count ); return 0; }