#include <bits/stdc++.h>
using namespace std;
int ReadInt() {
  int t;
  cin >> t;
  return t;
}
long long ReadLong() {
  long long t;
  cin >> t;
  return t;
}
int Vis[101][101];
vector<pair<int, int> > Road;
int main() {
  int n, m;
  cin >> n >> m;
  if (m % 2 == 0 || n % 2 == 0) {
    if ((n % 2 == 0 && m % 2 != 0 && m != 1) || (n == 2 && m == 1)) {
      cout << 0 << "\n";
      int x = 1, y = 1;
      Road.push_back({x, y});
      Vis[x][y] = 1;
      while (1) {
        if (x + 1 <= n && !Vis[x + 1][y]) {
          x++;
          Road.push_back({x, y});
          Vis[x][y] = 1;
        } else if (y + 1 <= m && !Vis[x][y + 1]) {
          y++;
          Road.push_back({x, y});
          Vis[x][y] = 1;
        } else if (y - 1 > 0 && !Vis[x][y - 1]) {
          y--;
          Road.push_back({x, y});
          Vis[x][y] = 1;
        } else if (x - 1 > 0 && !Vis[x - 1][y]) {
          x--;
          Road.push_back({x, y});
          Vis[x][y] = 1;
        } else {
          Road.push_back({1, 1});
          break;
        }
      }
      for (int i = 0; i < Road.size(); i++)
        cout << Road[i].first << " " << Road[i].second << "\n";
    } else if ((m % 2 == 0 && n != 1) || (n == 1 && m == 2)) {
      cout << 0 << "\n";
      int x = 1, y = 1;
      Road.push_back({x, y});
      Vis[x][y] = 1;
      while (1) {
        if (x + 1 <= n && !Vis[x + 1][y]) {
          x++;
          Road.push_back({x, y});
          Vis[x][y] = 1;
        } else if (y + 1 <= m && !Vis[x][y + 1]) {
          y++;
          Road.push_back({x, y});
          Vis[x][y] = 1;
        } else if (x - 1 > 0 && !Vis[x - 1][y]) {
          x--;
          Road.push_back({x, y});
          Vis[x][y] = 1;
        } else if (y - 1 > 0 && !Vis[x][y - 1]) {
          y--;
          Road.push_back({x, y});
          Vis[x][y] = 1;
        } else {
          Road.push_back({1, 1});
          break;
        }
      }
      for (int i = 0; i < Road.size(); i++)
        cout << Road[i].first << " " << Road[i].second << "\n";
    } else {
      cout << 1 << "\n";
      int x = 1, y = 1;
      Road.push_back({x, y});
      Vis[x][y] = 1;
      while (1) {
        if (x + 1 <= n && !Vis[x + 1][y]) {
          x++;
          Road.push_back({x, y});
          Vis[x][y] = 1;
        } else if (y + 1 <= m && !Vis[x][y + 1]) {
          y++;
          Road.push_back({x, y});
          Vis[x][y] = 1;
        } else if (x - 1 > 0 && !Vis[x - 1][y]) {
          x--;
          Road.push_back({x, y});
          Vis[x][y] = 1;
        } else if (y - 1 > 0 && !Vis[x][y - 1]) {
          y--;
          Road.push_back({x, y});
          Vis[x][y] = 1;
        } else {
          cout << x << " " << y << " " << 1 << " " << 1 << "\n";
          break;
        }
      }
      for (int i = 0; i < Road.size(); i++)
        cout << Road[i].first << " " << Road[i].second << "\n";
      cout << 1 << " " << 1 << "\n";
    }
  } else {
    cout << 1 << "\n";
    int x = 1, y = 1;
    Road.push_back({x, y});
    Vis[x][y] = 1;
    while (1) {
      if (x + 1 <= n && !Vis[x + 1][y]) {
        x++;
        Road.push_back({x, y});
        Vis[x][y] = 1;
      } else if (y + 1 <= m && !Vis[x][y + 1]) {
        y++;
        Road.push_back({x, y});
        Vis[x][y] = 1;
      } else if (x - 1 > 0 && !Vis[x - 1][y]) {
        x--;
        Road.push_back({x, y});
        Vis[x][y] = 1;
      } else if (y - 1 > 0 && !Vis[x][y - 1]) {
        y--;
        Road.push_back({x, y});
        Vis[x][y] = 1;
      } else {
        cout << x << " " << y << " " << 1 << " " << 1 << "\n";
        break;
      }
    }
    for (int i = 0; i < Road.size(); i++)
      cout << Road[i].first << " " << Road[i].second << "\n";
    cout << 1 << " " << 1 << "\n";
  }
  return 0;
}
