#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 10;
const int mod = 1e9 + 7;
const int inf = 0x3f3f3f3f;
int n, m, x, y;
namespace FastIO {
template <typename tp>
inline void read(tp &x) {
  x = 0;
  register char c = getchar();
  register bool f = 0;
  for (; c < '0' || c > '9'; f |= (c == '-'), c = getchar())
    ;
  for (; c >= '0' && c <= '9'; x = (x << 3) + (x << 1) + c - '0', c = getchar())
    ;
  if (f) x = -x;
}
template <typename tp>
inline void write(tp x) {
  if (x == 0) return (void)(putchar('0'));
  if (x < 0) putchar('-'), x = -x;
  int pr[20];
  register int cnt = 0;
  for (; x; x /= 10) pr[++cnt] = x % 10;
  while (cnt) putchar(pr[cnt--] + '0');
}
template <typename tp>
inline void writeln(tp x) {
  write(x);
  putchar('\n');
}
}  // namespace FastIO
using namespace FastIO;
void Out_Point(int x, int y) {
  write(x);
  putchar(' ');
  writeln(y);
}
void Out_Road(int bx, int by, int ex, int ey) {
  int dx, dy;
  if (bx == ex) {
    dx = 0;
    dy = (by < ey) ? 1 : -1;
  } else {
    dy = 0;
    dx = (bx < ex) ? 1 : -1;
  }
  while (bx != ex || by != ey) {
    bx += dx;
    by += dy;
    Out_Point(bx, by);
  }
}
void Solve1() {
  puts("0");
  x = 1, y = 1;
  Out_Point(x, y);
  Out_Road(x, y, 1, m);
  x = 1, y = m;
  Out_Road(x, y, n, m);
  x = n, y = m;
  Out_Road(x, y, x, y - 1);
  y--;
  while (!(x == n && y == 1)) {
    if (x == 2)
      Out_Road(x, y, n, y), x = n;
    else if (x == n)
      Out_Road(x, y, 2, y), x = 2;
    Out_Road(x, y, x, y - 1);
    y--;
  }
  Out_Road(x, y, 1, 1);
}
void Solve2() {
  puts("1");
  printf("%d %d 1 1\n", n, m);
  x = 1, y = 1;
  Out_Point(x, y);
  Out_Road(x, y, 1, m);
  x = 1, y = m;
  while (!(x == n && y == m)) {
    Out_Road(x, y, x + 1, y);
    x++;
    if (y == 1)
      Out_Road(x, y, x, m), y = m;
    else if (y == m)
      Out_Road(x, y, x, 1), y = 1;
  }
  x = 1, y = 1;
  Out_Point(x, y);
}
void Solve3() {
  puts("0");
  Out_Point(1, 1);
  if (m == 3) {
    Out_Road(1, 1, 1, m);
    Out_Road(1, m, n, m);
    Out_Road(n, m, n, 1);
    Out_Road(n, 1, n - 1, 1);
    x = n - 1, y = 1;
    while (!(x == 1 && y == 1)) {
      if (y == 1)
        Out_Road(x, y, x, m - 1), y = m - 1;
      else if (y == m - 1)
        Out_Road(x, y, x, 1), y = 1;
      Out_Road(x, y, x - 1, y), x--;
    }
  } else if (n == 3) {
    Out_Road(1, 1, n, 1);
    Out_Road(n, 1, n, m);
    Out_Road(n, m, 1, m);
    Out_Road(1, m, 1, m - 1);
    x = 1, y = m - 1;
    while (!(x == 1 && y == 1)) {
      if (x == 1)
        Out_Road(x, y, n - 1, y), x = n - 1;
      else if (x == n - 1)
        Out_Road(x, y, 1, y), x = 1;
      Out_Road(x, y, x, y - 1), y--;
    }
  }
}
void Solve4() {
  puts("0");
  x = 1, y = 1;
  Out_Point(x, y);
  Out_Road(x, y, 1, m);
  x = 1, y = m;
  Out_Road(x, y, n, m);
  x = n, y = m;
  Out_Road(x, y, x, y - 1);
  y--;
  Out_Road(x, y, 2, y);
  x = 2;
  while (!(x == n - 1 && y == m - 2)) {
    if (y == 2)
      Out_Road(x, y, x, m - 2), y = m - 2;
    else
      Out_Road(x, y, x, 2), y = 2;
    Out_Road(x, y, x + 1, y), x++;
  }
  while (!(x == n && y == 1)) {
    if (x == n - 1)
      Out_Road(x, y, n, y), x = n;
    else if (x == n)
      Out_Road(x, y, n - 1, y), x = n - 1;
    Out_Road(x, y, x, y - 1), y--;
  }
  Out_Road(x, y, 1, 1);
}
void Solve5() {
  puts("0");
  x = 1, y = 1;
  Out_Point(x, y);
  Out_Road(1, 1, 1, m);
  Out_Road(1, m, n, m);
  Out_Road(n, m, n, m - 1);
  Out_Road(n, m - 1, 2, m - 1);
  x = 2, y = m - 1;
  while (!(x == n && y == m - 2)) {
    if (y == 2)
      Out_Road(x, y, x, m - 2), y = m - 2;
    else
      Out_Road(x, y, x, 2), y = 2;
    Out_Road(x, y, x + 1, y), x++;
  }
  Out_Road(x, y, n, 1);
  Out_Road(n, 1, 1, 1);
}
int main() {
  read(n);
  read(m);
  if (n + m == 2) {
    Out_Point(1, 1);
    return 0;
  }
  if (n == 2) {
    puts("0");
    Out_Point(1, 1);
    Out_Road(1, 1, 1, m);
    Out_Road(1, m, 2, m);
    Out_Road(2, m, 2, 1);
    Out_Road(2, 1, 1, 1);
    return 0;
  }
  if (m == 2) {
    puts("0");
    Out_Point(1, 1);
    Out_Road(1, 1, 1, 2);
    Out_Road(1, 2, n, 2);
    Out_Road(n, 2, n, 1);
    Out_Road(n, 1, 1, 1);
    return 0;
  }
  if (n == 1) {
    puts("1");
    printf("%d %d 1 1\n", n, m);
    Out_Point(1, 1);
    Out_Road(1, 1, n, m);
    Out_Point(1, 1);
    return 0;
  }
  if (m == 1) {
    puts("1");
    printf("%d %d 1 1\n", n, m);
    Out_Point(1, 1);
    Out_Road(1, 1, n, m);
    Out_Point(1, 1);
    return 0;
  }
  if (n % 2 == 0 && m % 2 == 0)
    Solve1();
  else if (n % 2 == 1 && m % 2 == 1)
    Solve2();
  else if (n == 3 || m == 3)
    Solve3();
  else if (n % 2 == 1 && m % 2 == 0)
    Solve4();
  else if (n % 2 == 0 && m % 2 == 1)
    Solve5();
  return 0;
}
