public void solve() throws IOException {
    boolean start = true;
    while (start) {
      int width = nextInt();
      int height = nextInt();
      if (width == 0 && height == 0) {
        start = false;
        break;
      }
      int[][] arr = new int[width][height];
      maxs = new int[width][height];
      for (int x = 0; x < width; x++) {
        for (int y = 0; y < height; y++) {
          arr[x][y] = nextInt();
        }
      }
      int max = 0;
      for (int x = 0; x < width - max; x++) {
        for (int y = 0; y < height - max; y++) {
          if (arr[x][y] == 1) {
            // System.out.println(x + " " + y + " " + maxsq(arr, x, y));
            max = Math.max(max, maxsq(arr, x, y));
          }
        }
      }
      System.out.println(max);
      // for(int x = 0; x < width; x++)
      // {
      // for(int y = 0; y < height; y++)
      // System.out.print(maxs[x][y] + " ");
      // System.out.println();
      // }
    }
  }