#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
#define rrep(i, n) for (int i = n - 1; i >= 0; i--)
using namespace std;
#define INF ((1<<30)-1)
#define LINF (1LL<<60)
#define EPS (1e-10)
typedef long long ll;
typedef pair<ll, ll> P;
const int MOD = 1000000007;
const int MOD2 = 998244353;

ll a[310][310];
bool ok[310];
ll ans = LINF;

int main(){
    int n, m;
    cin >> n >> m;
    rep(i, n) rep(j, m) cin >> a[i][j], a[i][j]--;

    rep(i, 310) ok[i] = 1;

    rep(i, m){
        int selected[310] = {};
        rep(j, n){
            rep(k, m){
                if (ok[a[j][k]]) {
                    selected[a[j][k]]++;
                    break;
                }
            }
        }
        ll mx = 0, idx = -1;
        rep(j, m){
            if(selected[j] == 0) continue;
            if(selected[j] > mx){
                mx = selected[j];
                idx = j;
            }
        }
        ans = min(ans, mx);
        ok[idx] = 0;
    }

    cout << ans << endl;

    return 0;
}

#include<bits/stdc++.h>
#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
using namespace std;
int main(){
  int H,W,i,j,a;scanf("%d%d",&H,&W);
  bool odd[H][W];
  for(i=0;i<H;i++){
    for(j=0;j<W;j++){
      scanf("%d",&a);
      odd[i][j] = a&1;
    }
  }
  bool coin = false;vector<pair<pair<int,int>,pair<int,int>>> v;
  i = 0;j = 0;int ni,nj;
  while(true){
    if((!(i&1)) && j+1 == W){
      ni = i+1;nj = j;
    }
    else if(i&1 && j == 0){
      ni = i+1;nj = j;
    }
    else if(!(i&1)){
      ni = i;nj = j+1;
    }
    else{
      ni = i;nj = j-1;
    }
    if(ni == H) break;
    if(odd[i][j]){
      if(coin == false){
        coin = true;
        v.push_back(make_pair(make_pair(i,j),make_pair(ni,nj)));
      }
      else{
        coin = false;
      }
    }
    else{
      if(coin == true){
        v.push_back(make_pair(make_pair(i,j),make_pair(ni,nj)));
      }
    }
    i = ni;j = nj;
  }
  printf("%d\n",v.size());
  for(i=0;i<v.size();i++) printf("%d %d %d %d\n",v[i].first.first+1,v[i].first.second+1,v[i].second.first+1,v[i].second.second+1);
}