using System; using System.IO; using System.Collections.Generic; using static System.Console; using static System.Math; class Start{ static void Solve(){ var n=int.Parse(ReadLine()); var a=new List(); var k=ReadLine().Split(); for(int i=n-1;i>=0;i--)a.Add(int.Parse(k[i])); var ans=0; while(true){ var max=-1; var i=1; var oldi=0; var j=0; while(i!=a.Count){ if(a[i]>a[oldi]&&a[oldi]>max){ j=oldi; max=a[oldi]; } if(a[i]!=-1)oldi=i; i++; } if(max==-1)break; ans++; a[j]=-1; a.Add(max); } WriteLine(ans); } static void Main(){ var sw=new StreamWriter(OpenStandardOutput()){AutoFlush=false}; SetOut(sw); Solve(); Out.Flush(); } const long MOD=1000000007L; static void Swap(ref T a,ref T b){T c=a;a=b;b=c;} } class Pair : IComparable> where T : IComparable where U : IComparable { public T F; public U S; public Pair(T v1, U v2) { this.F = v1; this.S = v2; } public int CompareTo(Pair a) => F.CompareTo(a.F) != 0 ? F.CompareTo(a.F) : S.CompareTo(a.S); public override string ToString() => F + " " + S; } /*class Pair : IComparable> where T1 : IComparable where T2 : IComparable { public T1 F;public T2 S; public Pair(T1 f,T2 s){F=f;S=s;} public long CompareTo(Pair p)=>F.CompareTo(p.F)!=0?F.CompareTo(p.F):S.CompareTo(p.S); public override string ToString()=>F+" "+S; }*/