#include <bits/stdc++.h>

#define el '\n'
#define fi first
#define sec second
#define pb push_back
#define int long long
#define pii pair<int,int>
#define sz(v) (int)(v).size()
#define all(v) (v).begin(),(v).end()
#define FOR(i, a, b) for(int i = (a), _b = (b); i <= _b; i++)
#define REP(i, a, b) for(int i = (a), _b = (b); i >= _b; i--)

using namespace std;

const int INF = (int)1e18 + 462010;
const int MAX_A = 100;
const int MAX_N = 2e5;
const int BS = 450;

struct Disjoint_Set_Union {
    int parent[MAX_A + 5];
    int root[MAX_A + 5];
    int color[MAX_A + 5];

    void build() {
        FOR(i, 1, MAX_A) {
            parent[i] = i;
            root[i] = i;
            color[i] = i;
        }
    }

    int get(int u) {
        if (u == parent[u]) return u;
        return parent[u] = get(parent[u]);
    }

    void unite(int x, int y) {
        if (x == y || root[x] == 0) return;

        if (root[y] == 0) {
            root[y] = root[x];
            color[root[y]] = y;
            root[x] = 0;
        } else {
            parent[root[x]] = root[y];
            root[x] = 0;
        }
    }

    int value(int u) {
        return color[get(u)];
    }
}dsu[MAX_N / BS + 5];

int a[MAX_N + 5];
int n, q;

void Input(){
    cin >> n >> q;
    FOR(i, 1, n) cin >> a[i];
}

void re_build(int l, int r, int x, int y){
    int block = l / BS;
    FOR(i, max(1LL, block * BS), min(n, (block + 1) * BS - 1)){
        a[i] = dsu[block].value(a[i]);
        if(l <= i && i <= r && a[i] == x) a[i] = y;
    }
    dsu[block].build();
}

void process(int l, int r, int x, int y){
    int bl = l / BS, br = r / BS;

    if(bl == br){
        re_build(l, r, x, y);
        return;
    }

    FOR(i, bl + 1, br - 1) dsu[i].unite(x, y);
    re_build(l, (bl + 1) * BS - 1, x, y);
    re_build(br * BS, r, x, y);
}

void Prepare(){
    FOR(i, 0, n / BS) dsu[i].build();
}

void Solve(){
    while(q--){
        int l, r, x, y;
        cin >> l >> r >> x >> y;
        process(l, r, x, y);
    }
    FOR(i, 1, n) cout << dsu[i / BS].value(a[i]) << " ";
}

signed main(){
    freopen("rangeset.INP", "r", stdin);
    freopen("rangeset.OUT", "w", stdout);
    ios_base::sync_with_stdio(0);
    cin.tie(0);

    Input();
    Prepare();
    Solve();

    return 0;
}
