/LCSUB - Dãy con có giá trị liên tiếp dài nhất

<Problem>

http://ntucoder.net/Problem/Details/5552
              Uses Crt;
      Var n,k,num,i,d,c,dem:longint; a:array[0..100000] of boolean;
      Begin
          readln(n,k);
          for i:=1 to k do
          begin
              read(num);
              a[num]:=true;
          end;
          dem:=1;
          for i:=1 to n do
          begin
              d:=i; c:=i;
              if dem>n-i+1 then break;
              
              while a[c] do inc(c);
              if a[0] then
              begin
                  inc(c);
                  while a[c] do inc(c);
              end;
              if dem<c-d then dem:=c-d;
          end;
          writeln(dem);
          readln;
      End.