{
TASK: man
LANG: PASCAL
}

program man;
  const maxn=2000;
  var
    sbr,p,q,M,pom,i,j,s:longint;
    N:longint;
    A:array[0..maxN,0..maxn] of longint;
    B:array[0..maxN] of longint;

begin

  readln(M);

  for i:=0 to maxN do
    for j:=0 to maxn do
      A[i,j]:=0;

  for i:=1 to maxn  do
    B[i]:=0;

  pom:=1 ;   s:=0;
  repeat
    begin
      readln(p,q);
      if s<p then
        s:=q;
      if s<q then
        s:=q;
      A[p,q]:=1;
      A[q,p]:=1;
      inc(pom);
    end;
  until pom>M;

  p:=0; q:=1;
  for i:=p to s+1 do
    begin
      for j:=q to s+1 do
        if A[i,j] = 1 then
          B[j]:=1;
       inc(q);
       inc(p);
     end;

  sbr:=0;
  for i:=0 to maxn do
    sbr:=B[i]+sbr ;

 writeln(sbr);



end.
