#include<bits/stdc++.h>

using namespace std;

#define ll  long long
#define ld  double

#define all(x)  x.begin(),x.end()
#define sz(x)   (int)x.size()

#define pb  emplace_back
#define X   first
#define Y   second

const int   N   = 2e5 + 5;

typedef pair<int,int>   ii;

vector<int> g[N];

int par[N];
int deg[N];

int main()  {
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);

    int n;  cin >> n;
    int m;  cin >> m;

    for(int i = 1 ; i < n + m ; ++i)    {
        int x;  cin >> x;
        int y;  cin >> y;

        g[x].pb(y);
        deg[y]++;
    }
    queue<int>  qu;
    vector<int> tp;

    for(int i = 1 ; i <= n ; ++i)
        if(!deg[i]) qu.push(i);

    while (qu.size())   {
        int u = qu.front(); qu.pop();

        tp.pb(u);

        for(int v : g[u])   {
            deg[v]--;
            if(!deg[v])
                qu.push(v);
        }
    }
    for(int x : tp)
    for(int v : g[x])
        par[v] = x;

    for(int i = 1 ; i <= n ; ++i)
        cout << par[i] << "\n";
}

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
const int MOD = 1000000007;

int main()
{
    int h, w;
    cin >> h >> w;
    int a[h][w];
    rep(i, h)
    {
        rep(j, w) cin >> a[i][j];
    }

    int cnt = 0;
    vector<tuple<int, int, int, int>> ans;
    //現在位置を示す値
    int i = 0, j = 0;
    while (1)
    {
        if (i % 2 == 0)
        {
            if (j == w - 1)
            {
                if (i == h - 1)
                    goto end;
                if (a[i][j] % 2 == 1)
                {
                    cnt++;
                    ans.emplace_back(i + 1, j + 1, i + 2, j + 1);
                    a[i + 1][j]++;
                }
                i++;
            }
            else
            {
                if (a[i][j] % 2 == 1)
                {
                    cnt++;
                    ans.emplace_back(i + 1, j + 1, i + 1, j + 2);
                    a[i][j + 1]++;
                }
                j++;
            }
        }
        if (i % 2 == 1)
        {
            if (j == 0)
            {
                if (i == h - 1)
                    goto end;
                if (a[i][j] % 2 == 1)
                {
                    cnt++;
                    ans.emplace_back(i + 1, j + 1, i + 2, j + 1);
                    a[i + 1][j]++;
                }
                i++;
            }
            else
            {
                if (a[i][j] % 2 == 1)
                {
                    cnt++;
                    ans.emplace_back(i + 1, j + 1, i + 1, j);
                    a[i][j - 1]++;
                }
                j--;
            }
        }
    }
end:
    cout << cnt << endl;
    rep(i, cnt)
    {
        cout << get<0>(ans[i]) << " " << get<1>(ans[i]) << " " << get<2>(ans[i]) << " " << get<3>(ans[i]) << endl;
    }
}