#include <bits/stdc++.h>
using namespace std;
int main() {
  int N;
  int M;
  scanf("%d %d", &N, &M);
  if (M == 1) {
    if (N == 2) {
      printf("0\n 1 1\n 2 1\n 1 1\n");
      return 0;
    }
    printf("1\n");
    printf("%d %d 1 1\n", N, M);
    int x = 1;
    int y = 1;
    printf("%d %d\n", x, y);
    for (int n = 0; n < N - 1; n++) {
      x++;
      printf("%d %d\n", x, y);
    }
    printf("1 1\n");
  } else if (N == 1) {
    if (M == 2) {
      printf("0\n 1 1\n 1 2\n 1 1\n");
      return 0;
    }
    printf("1\n");
    printf("%d %d 1 1\n", N, M);
    int x = 1;
    int y = 1;
    printf("%d %d\n", x, y);
    for (int n = 0; n < M - 1; n++) {
      y++;
      printf("%d %d\n", x, y);
    }
    printf("1 1\n");
  } else if (N % 2 == 0) {
    printf("0\n");
    int x = 1;
    int y = 1;
    printf("%d %d\n", x, y);
    y++;
    printf("%d %d\n", x, y);
    for (int n = 0; n < N; n++) {
      int add = 0;
      if (n % 2 == 0) {
        add = 1;
      } else {
        add = -1;
      }
      for (int m = 0; m < M - 2; m++) {
        y += add;
        printf("%d %d\n", x, y);
      }
      if (n != N - 1) {
        x++;
        printf("%d %d\n", x, y);
      }
    }
    y--;
    printf("%d %d\n", x, y);
    for (int n = 0; n < N - 1; n++) {
      x--;
      printf("%d %d\n", x, y);
    }
  } else if (M % 2 == 0) {
    swap(N, M);
    printf("0\n");
    int x = 1;
    int y = 1;
    printf("%d %d\n", y, x);
    y++;
    printf("%d %d\n", y, x);
    for (int n = 0; n < N; n++) {
      int add = 0;
      if (n % 2 == 0) {
        add = 1;
      } else {
        add = -1;
      }
      for (int m = 0; m < M - 2; m++) {
        y += add;
        printf("%d %d\n", y, x);
      }
      if (n != N - 1) {
        x++;
        printf("%d %d\n", y, x);
      }
    }
    y--;
    printf("%d %d\n", y, x);
    for (int n = 0; n < N - 1; n++) {
      x--;
      printf("%d %d\n", y, x);
    }
  } else {
    printf("%d\n", 1);
    printf("%d %d 1 1\n", N, M);
    int x = 1;
    int y = 1;
    printf("%d %d\n", x, y);
    for (int n = 0; n < N; n++) {
      int add = 0;
      if (n % 2 == 0) {
        add = 1;
      } else {
        add = -1;
      }
      for (int m = 0; m < M - 1; m++) {
        y += add;
        printf("%d %d\n", x, y);
      }
      if (n != N - 1) {
        x++;
        printf("%d %d\n", x, y);
      }
    }
    printf("1 1\n");
  }
}
