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