#include <bits/stdc++.h>
using namespace std;
int n, m;
int b[100000] = {0}, a[200000][2] = {0}, minp[512][2] = {0}, maxpl = 0,
    mincosts[100001][3];
int main() {
  cin >> n >> m;
  for (int i = 0; i < n; i++) {
    int f;
    cin >> f;
    int like = 0, ing;
    for (int j = 0; j < f; j++) {
      cin >> ing;
      ing--;
      like |= (1 << ing);
    }
    b[i] = like;
  }
  for (int i = 0; i < m; i++) {
    int c, r, contains = 0, ing;
    cin >> c >> r;
    a[i][0] = c;
    for (int j = 0; j < r; j++) {
      cin >> ing;
      ing--;
      contains |= (1 << ing);
    }
    a[i][1] = contains;
  }
  for (int i = 0; i < 512; i++) {
    int min1 = INT_MAX, idx1 = -1, min2 = INT_MAX, idx2 = -1;
    for (int j = 0; j < m; j++) {
      if ((a[j][1] | i) == a[j][1]) {
        if (a[j][0] < min1) {
          min2 = min1;
          min1 = a[j][0];
          idx2 = idx1;
          idx1 = j;
        } else if (a[j][0] < min2) {
          min2 = a[j][0];
          idx2 = j;
        }
      }
    }
    minp[i][0] = idx1;
    minp[i][1] = idx2;
  }
  for (int i = 0; i <= n; i++) {
    mincosts[i][0] = INT_MAX;
  }
  for (int i = 0; i < 512; i++) {
    int pl = 0;
    for (int j = 0; j < n; j++) {
      if ((i | b[j]) == i) pl++;
    }
    int curmincost = INT_MAX, x = -1, y = -1;
    for (int j = 0; j < m; j++) {
      int mask = i ^ (i & a[j][1]);
      if ((minp[mask][0] != -1) &&
          ((minp[mask][0] != j) || (minp[mask][1] != -1))) {
        int piz;
        if (minp[mask][0] == j)
          piz = minp[mask][1];
        else
          piz = minp[mask][0];
        if (a[piz][0] + a[j][0] < curmincost) {
          x = j;
          y = piz;
          curmincost = a[piz][0] + a[j][0];
        }
      }
    }
    if (curmincost < mincosts[pl][0]) {
      mincosts[pl][0] = curmincost;
      mincosts[pl][1] = x;
      mincosts[pl][2] = y;
    }
  }
  int pleased = n;
  while (mincosts[pleased][0] == INT_MAX) {
    pleased--;
  }
  cout << mincosts[pleased][1] + 1 << " " << mincosts[pleased][2] + 1 << "\n";
  return 0;
}
