#include <bits/stdc++.h>
#define MAXN 300010
#define ll long long
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define pii pair<int, int>

using namespace std;

void solve()
{
    bool t1 = true;
    int n, m;
    cin >> n >> m;
    vector<int> a(n+1),  b(n+1);
    for (int i = 1; i <= n; i++)
    {
        cin >> a[i] >> b[i];
    }
    vector<int> c(m+1), d(m+1);
    for (int i = 1; i <= m; i++)
    {
        cin >> c[i] >> d[i];
        if (!(a[i] <= c[i] && c[i] <= b[i] && b[i] <= d[i]))
            t1 = false;
    }
    int k = 0;
    if (n == m && t1)
    {
        k = n;
        cout << k << '\n';
        for (int i = 1; i <= n; i++)
        {
            cout << i << ' ' << i << ' ' << b[i] << '\n';
        }
        return;
    }
    cout << k << '\n';
}

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

    int t = 1;
    //cin >> t;
    while (t--)
    {
        solve();
    }
    return 0;
}