// nongdanjohn - THPTNguyen-Quang-Dieu
const maxN = 100001;
var N: longint;
A: array[1..maxN] of longint;
Link,Head: array[1..maxN] of longint;
Free: array[1..maxN] of boolean;
Procedure Enter;
var i: longint;
begin
Readln(N);
For i:=1 to N do Read(A[i]);
For i:=N downto 1 do
if Free[A[i]] then
begin
Head[A[i]]:=i;
Link[i]:=i;
Free[A[i]]:=False;
end else
begin
link[i]:=head[A[i]];
Head[A[i]]:=i;
end;
end;
Procedure Sort(L,H: longint);
var i,j,k,t: longint;
begin
i:=l; j:=h; k:=A[(l+h) div 2];
repeat
while A[i]<k do inc(i);
while A[j]>k do dec(j);
if i<=j then
begin
t:=A[i]; A[i]:=A[j]; A[j]:=t;
inc(i); dec(j);
end;
until i>j;
if l<j then sort(l,j);
if i<h then sort(i,h);
end;
procedure solve;
var i,j,res: longint;
begin
Fillchar(Free, sizeof(Free), true);
res:=0;
for i:=1 to n do
begin
j:=head[A[i]];
if Free[j] then
begin
inc(res);
Free[j]:=False; Free[j+1]:=False; Free[j-1]:=False;
end;
head[A[i]]:=Link[j];
end;
Writeln(Res);
end;
Begin
Assign(Input,''); Reset(Input);
Enter;
Sort(1,n);
solve;
End.
Ly8gbm9uZ2RhbmpvaG4gLSBUSFBUTmd1eWVuLVF1YW5nLURpZXUKY29uc3QgbWF4TiA9IDEwMDAwMTsKdmFyIE46IGxvbmdpbnQ7CiAgICBBOiBhcnJheVsxLi5tYXhOXSBvZiBsb25naW50OwogICAgTGluayxIZWFkOiBhcnJheVsxLi5tYXhOXSBvZiBsb25naW50OwogICAgRnJlZTogYXJyYXlbMS4ubWF4Tl0gb2YgYm9vbGVhbjsKClByb2NlZHVyZSBFbnRlcjsKdmFyIGk6IGxvbmdpbnQ7CmJlZ2luCiAgICBSZWFkbG4oTik7CiAgICBGb3IgaTo9MSB0byBOIGRvIFJlYWQoQVtpXSk7CiAgICBGb3IgaTo9TiBkb3dudG8gMSBkbwogICAgICBpZiBGcmVlW0FbaV1dIHRoZW4KICAgICAgICBiZWdpbgogICAgICAgICAgSGVhZFtBW2ldXTo9aTsKICAgICAgICAgIExpbmtbaV06PWk7CiAgICAgICAgICBGcmVlW0FbaV1dOj1GYWxzZTsKICAgICAgICBlbmQgZWxzZQogICAgICAgIGJlZ2luCiAgICAgICAgICBsaW5rW2ldOj1oZWFkW0FbaV1dOwogICAgICAgICAgSGVhZFtBW2ldXTo9aTsKICAgICAgICBlbmQ7CmVuZDsKClByb2NlZHVyZSBTb3J0KEwsSDogbG9uZ2ludCk7CnZhciBpLGosayx0OiBsb25naW50OwpiZWdpbgogICAgaTo9bDsgajo9aDsgazo9QVsobCtoKSBkaXYgMl07CiAgICByZXBlYXQKICAgICAgd2hpbGUgQVtpXTxrIGRvIGluYyhpKTsKICAgICAgd2hpbGUgQVtqXT5rIGRvIGRlYyhqKTsKICAgICAgaWYgaTw9aiB0aGVuCiAgICAgICAgYmVnaW4KICAgICAgICAgIHQ6PUFbaV07IEFbaV06PUFbal07IEFbal06PXQ7CiAgICAgICAgICBpbmMoaSk7IGRlYyhqKTsKICAgICAgICBlbmQ7CiAgICB1bnRpbCBpPmo7CiAgICBpZiBsPGogdGhlbiBzb3J0KGwsaik7CiAgICBpZiBpPGggdGhlbiBzb3J0KGksaCk7CmVuZDsKCnByb2NlZHVyZSBzb2x2ZTsKdmFyIGksaixyZXM6IGxvbmdpbnQ7CmJlZ2luCiAgICBGaWxsY2hhcihGcmVlLCBzaXplb2YoRnJlZSksIHRydWUpOwogICAgcmVzOj0wOwogICAgZm9yIGk6PTEgdG8gbiBkbwogICAgICBiZWdpbgogICAgICAgIGo6PWhlYWRbQVtpXV07CiAgICAgICAgaWYgRnJlZVtqXSB0aGVuCiAgICAgICAgICBiZWdpbgogICAgICAgICAgICBpbmMocmVzKTsKICAgICAgICAgICAgRnJlZVtqXTo9RmFsc2U7IEZyZWVbaisxXTo9RmFsc2U7IEZyZWVbai0xXTo9RmFsc2U7CiAgICAgICAgICBlbmQ7CiAgICAgICAgaGVhZFtBW2ldXTo9TGlua1tqXTsKICAgICAgZW5kOwogICAgV3JpdGVsbihSZXMpOwplbmQ7CgpCZWdpbgogICAgQXNzaWduKElucHV0LCcnKTsgUmVzZXQoSW5wdXQpOwogICAgRW50ZXI7CiAgICBTb3J0KDEsbik7CiAgICBzb2x2ZTsKRW5kLg==