#include <bits/stdc++.h>
using namespace std;
int main() {
  int N, M;
  while (~scanf("%d%d", &N, &M)) {
    if (N == 1 && M == 2) {
      printf("0\n1 1\n1 2\n1 1\n");
    } else if (N == 2 && M == 1) {
      printf("0\n1 1\n2 1\n1 1\n");
    } else if ((N % 2 == 1 && M % 2 == 1) || N == 1 || M == 1) {
      printf("1\n%d %d 1 1\n", N, M);
      for (int i = 1; i <= N; i++) {
        for (int j = 1; j <= M; j++) {
          if (i % 2 == 1)
            printf("%d %d\n", i, j);
          else
            printf("%d %d\n", i, M - j + 1);
        }
      }
      printf("1 1\n");
    } else {
      printf("0\n");
      if (N % 2 == 0) {
        for (int i = 1; i <= M; i++) printf("1 %d\n", i);
        for (int i = 2; i <= N; i++) {
          for (int j = 2; j <= M; j++) {
            if (i % 2 == 0)
              printf("%d %d\n", i, M - j + 2);
            else
              printf("%d %d\n", i, j);
          }
        }
        for (int i = N; i >= 1; i--) printf("%d 1\n", i);
      } else if (M % 2 == 0) {
        for (int i = 1; i <= N; i++) printf("%d 1\n", i);
        for (int j = 2; j <= M; j++) {
          for (int i = 2; i <= N; i++) {
            if (j % 2 == 0)
              printf("%d %d\n", N - i + 2, j);
            else
              printf("%d %d\n", i, j);
          }
        }
        for (int i = M; i >= 1; i--) printf("1 %d\n", i);
      }
    }
  }
  return 0;
}
