program lenta_su_skylemis;
  { 19 u‘davinys }
  const MAX = 100; { maksimalus lentos dydis }
  type lenta = array [1..MAX, 1..MAX] of (kvadr, skyle);

  function min (a, b, c : integer) : integer;
    { randa ma‘iausi… iž trij— skai‡i— }
    var mn : integer;
  begin
    mn := a;
    if mn > b
       then mn := b;
    if mn > c
       then mn := c;
    min := mn
  end;

  function kvadratas (lent : lenta;
                      m, n : integer) : integer;
    var did, i, j : integer;
        c1, c2 : array [1..MAX] of integer; { viena lentel‚s c eilut‚ }
  begin
    did := 0; { did‘iausio kvadrato kražtin‚ }
    { u‘pildome pirm…j… lentel‚s c eilutŠ }
    for j := 1 to n do
      if lent [1, j] = skyle
         then c1[j] := 0
         else begin
                c1[j] := 1;
                if c1[j] > did
                   then did := c1[j];
              end;
    { pildome kitas lentel‚s c eilutes }
    for i := 2 to m do
      begin
        for j := 1 to n do
          begin
            if lent[i, j] = skyle
               then c2[j] := 0
               else if j = 1
                       then c2[j] := 1
                       else c2[j] :=
                                   min (c2[j - 1], c1[j - 1], c1[j]) + 1;
            if did < c2[j]
               then did := c2[j];
          end;
        c1 := c2;
      end;
    kvadratas := did;
  end;

  var f : text;
      v : string;
      i, j, a, b, m, n, sk : integer;
      lent : lenta;
begin
  write ('­veskite pradini— duomen— bylos vard…: ');
  readln (v);
  assign (f, v);
  reset (f);
  readln (f, m, n);
  for i := 1 to m do
    for j := 1 to n do
      lent [i, j] := kvadr;
  readln (f, sk);
  for i := 1 to sk do
    begin
      readln (f, a, b);
      lent[a, b] := skyle;
    end;
  writeln (kvadratas (lent, m, n));
end.