#include <bits/stdc++.h>
#define ll long long

using namespace std;

void solve() {
    int n, m;
    cin >> n >> m;
    int a[n];
    int b[n];
    int c[m];
    int d[m];
    for (int i=0;i<n;i++) {
        int ax, bx;
        cin >> ax >> bx;
        a[i] = ax;
        b[i] = bx;
    }
    for (int i=0;i<m;i++) {
        int cx, dx;
        cin >> cx >> dx;
        c[i] = cx;
        d[i] = dx;
    }
    if (n == 1) {
        int available = b[0];
        for (int i = 0;i<m;i++) {
            available -= c[i];
        }
        for (int i=0;i<m;i++) {
            if (c[i] + available >= d[i]) {
                cout << d[i] << " ";
                available -= (d[i]-c[i]);
            }
            if (c[i] + available < d[i]) {
                cout << c[i] + available << " ";
                available = 0;
            }
        }
        return;
    }
    int matrix[n][m];
    for (int i = 0;i<n;i++) {
        if (a[i] == 0) {
            for (int j = 0;j<m;j++) {
                matrix[i][j] = 0;
            }
        }
    }
    for (int i = 0;i<m;i++) {
        if (c[i] == 0) {
            for (int j = 0;j<n;j++) {
                matrix[j][i] = 0;
            }
        }
    }
    for (int i=0;i<n;i++) {
        for (int j=0;j<m;j++) {
            cout << matrix[i][j];
        }
        cout << "\n";
    }
}


int main()
{
    solve();
    //cout << "Hello world!" <<endl;
    return 0;
}