#include <bits/stdc++.h>
using namespace std;
const int MOD = 1000000007;
void sync_stdio() {
  cin.tie(NULL);
  ios_base::sync_with_stdio(false);
}
struct Sync_stdio {
  Sync_stdio() {
    cin.tie(NULL);
    ios_base::sync_with_stdio(false);
  }
} _sync_stdio;
struct FAIL {
  FAIL() {
    cout << "CHANGE!!!"
         << "\n";
  }
};
int n, m;
vector<vector<int>> g;
double get_rand(long long low, long long high) {
  return rand() / (RAND_MAX + 1.0) * (high - low) + low;
}
vector<int> cl;
int maxc = 0;
vector<int> ans;
int main() {
  srand(191229);
  scanf("%d%d", &n, &m);
  g.resize(n);
  for (int i = (0); i < (m); ++i) {
    int x, y;
    scanf("%d%d", &x, &y);
    --x, --y;
    g[x].push_back(y);
    g[y].push_back(x);
  }
  vector<vector<int>> team(n);
  for (int i = (0); i < (n); ++i) {
    int k;
    scanf("%d", &k);
    team[i].resize(k);
    for (int j = (0); j < (k); ++j) {
      scanf("%d", &team[i][j]);
      maxc = max(maxc, team[i][j]);
      --team[i][j];
    }
  }
  vector<int> ans(n);
  cl.resize(maxc);
  while (1) {
    for (int i = (0); i < (n); ++i) {
      ans[i] = team[i][get_rand(0, team[i].size())];
    }
    for (int i = (0); i < (maxc); ++i) {
      cl[i] = get_rand(0, 2);
    }
    int res = 0;
    for (int i = (0); i < (n); ++i) {
      for (auto j : g[i]) {
        if (cl[ans[i]] != cl[ans[j]]) {
          ++res;
        }
      }
    }
    if (res >= m) {
      break;
    }
  }
  for (auto &i : ans) {
    ++i;
  }
  for (auto &i : cl) {
    ++i;
  }
  for (auto __i : ans) cout << __i << " ";
  cout << "\n";
  cout.flush();
  ;
  for (auto __i : cl) cout << __i << " ";
  cout << "\n";
  cout.flush();
  ;
  return 0;
}
