#include <bits/stdc++.h>
using namespace std;
const int N = 100005;
int bit[N];
long long price[2][N];
pair<int, int> choose[2][N];
int main() {
  int i, j, k, l, a, b, d;
  long long c;
  int n, m;
  scanf("%d %d", &n, &m);
  for (i = 1; i <= n; i++) {
    scanf("%d", &a);
    for (j = 0; j < a; j++) {
      scanf("%d", &b);
      bit[i] |= (1 << (b - 1));
    }
  }
  for (i = 0; i < (1 << 9); i++) price[0][i] = price[1][i] = 1e18;
  pair<int, int> ans;
  long long p = 0, pp = 1e18;
  for (i = 1; i <= m; i++) {
    scanf("%lld %d", &c, &a);
    int now = 0;
    for (j = 0; j < a; j++) {
      scanf("%d", &b);
      now |= (1 << (b - 1));
    }
    for (k = 0; k < (1 << 9); k++) {
      if (price[1][k | now] > c + price[0][k]) {
        price[1][k | now] = c + price[0][k];
        choose[1][k | now] = {choose[0][k].first, i};
      }
    }
    if (price[0][now] > c) {
      price[0][now] = c;
      choose[0][now] = {i, 0};
    }
  }
  for (i = 0; i < (1 << 9); i++) {
    if (!choose[1][i].first) continue;
    int cnt = 0;
    for (j = 1; j <= n; j++) {
      if ((i & bit[j]) == bit[j]) cnt++;
    }
    if (cnt > p)
      p = cnt, pp = price[1][i], ans = choose[1][i];
    else if (cnt == p && pp > price[1][i])
      pp = price[1][i], ans = choose[1][i];
  }
  printf("%d %d", ans.first, ans.second);
  return 0;
}
