#include <bits/stdc++.h>
using namespace std;
struct Node { int x, y, c = -1; };
vector<Node> nodes;
vector<vector<int>> adj;
vector<bool> visited;
bool CanReaach(const int cur, const int dst, const int c1, const int c2) {
if (cur == dst) return true;
visited[cur] = true;
for (int u : adj[cur]) {
if (visited[u] || (nodes[u].c != c1 && nodes[u].c != c2)) continue;
if (CanReaach(u, dst, c1, c2)) return true;
}
return false;
}
void Coloring(const int cur, const int c1, const int c2) {
visited[cur] = true;
nodes[cur].c = (nodes[cur].c == c1 ? c2 : c1);
for (int u : adj[cur]) {
if (!visited[u] && (nodes[u].c == c1 || nodes[u].c == c2))
Coloring(u, c1, c2);
}
}
int main() {
cin.tie(0); ios::sync_with_stdio(false);
int n, m;
cin >> n >> m;
nodes.resize(n);
for (int i = 0; i < n; ++i)
cin >> nodes[i].x >> nodes[i].y;
adj.resize(n);
for (int i = 0, u, v; i < m; ++i) {
cin >> u >> v;
adj[u - 1].push_back(v - 1);
adj[v - 1].push_back(u - 1);
}
vector<int> order(n);
iota(order.begin(), order.end(), 0);
sort(order.begin(), order.end(), [&](int u, int v) {
return (nodes[u].y > nodes[v].y) ||
(nodes[u].y == nodes[v].y && nodes[u].x < nodes[v].x);
});
auto priority = [&](const int u, const int v) {
if (nodes[u].y == nodes[v].y && nodes[u].x < nodes[v].x) return 0;
else if (nodes[u].x == nodes[v].x && nodes[u].y > nodes[v].y) return 2;
else if (nodes[u].x < nodes[v].x && nodes[u].y > nodes[v].y) return 1;
else if (nodes[u].x > nodes[v].x && nodes[u].y > nodes[v].y) return 3;
else return 4;
};
for (int v = 0; v < n; ++v) {
sort(adj[v].begin(), adj[v].end(), [&](int u1, int u2) {
return priority(u1, v) < priority(u2, v);
});
}
visited.resize(n);
array<int, 4> idx;
array<bool, 4> color;
for (const int v : order) {
int deg = 0;
color.fill(false);
for (int u : adj[v])
if (nodes[u].c != -1) {
idx[deg++] = u;
color[nodes[u].c] = true;
}
bool can_color = false;
for (int c = 0; c < 4; ++c)
if (!color[c]) {
nodes[v].c = c;
can_color = true;
break;
}
if (can_color) continue;
fill(visited.begin(), visited.end(), false);
if (CanReaach(idx[0], idx[2], nodes[idx[0]].c, nodes[idx[2]].c)) {
fill(visited.begin(), visited.end(), false);
int v_c = nodes[idx[1]].c;
Coloring(idx[1], nodes[idx[1]].c, nodes[idx[3]].c);
nodes[v].c = v_c;
}
else {
fill(visited.begin(), visited.end(), false);
int v_c = nodes[idx[0]].c;
Coloring(idx[0], nodes[idx[0]].c, nodes[idx[2]].c);
nodes[v].c = v_c;
}
}
for (int v = 0; v < n; ++v)
cout << nodes[v].c + 1 << '\n';
return 0;
}