#define _CRT_SECURE_NO_DEPRECATE
#pragma comment (linker, "/STACK:30000000")

#include <string>
#include <vector>
#include <cmath>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
#include <iostream>
#include <cstdio>
#include <cassert>
#include <utility>

using namespace std;

#define IN_FILE "metro.in"
#define OUT_FILE "metro.out"

#define EPS 1E-8
const int INF = (int)1E+9;

#define forn(i, n) for (int i = 0; i < (int)(n); ++i)
#define forv(i, v) for (int i = 0; i < (int)(v.size()); ++i)
#define fors(i, s) for (int i = 0; i < (int)(s.length()); ++i)
#define all(a) a.begin(), a.end()
#define pb push_back
#define PII pair<int, int>
#define mp make_pair
#define VI vector<int>
#define VS vector<string>

const int NMAX = 20;

int n, k;
int kCircle;
vector< VI > ens;
int g[NMAX][NMAX];
bool cross[NMAX][NMAX];
bool up[NMAX];
int v[NMAX];

bool ans;

void outdata() {
    if (ans) printf("YES\n"); else printf("NO\n");
}

bool crossDuga(VI &a, VI &b) {
    if (a.size() + b.size() < 4) return false;
    if (a[0] == b[0] || a[0] == b[1] || a[1] == b[0] || a[1] == b[1]) return false;
    bool f = (b[0] < a[0] && a[0] < b[1]);
    bool c = (b[0] < a[1] && a[1] < b[1]);
    return f ^ c;
}

bool check() {
    forn(i, k) {
        forn(j, i) {
            if (cross[i][j] && g[i][j] == -1) return false;
            if (cross[i][j]) {
                if (v[i] == -1) v[i] = (int)up[i];
                if (v[i] != (int)up[i]) return false;
            }
        }
    }
    return true;
}

void solve() {
    ens.clear();
    kCircle = 0;
    ens.resize(k);
    memset(g, 255, sizeof g);
    forn(i, n) {
        int t;
        scanf("%d", &t);
        assert(2 <= t && t <= k);
        VI x(t), y;
        forn(j, t) scanf("%d", &x[j]);
        forn(j, t) assert(0 <= x[j] && x[j] < k);
            y = x; sort(all(y)); y.erase(unique(all(y)), y.end()); assert(x == y);
        if (x[0] != 0) {
            forn(u, t) --x[u];
            forn(u, t) forn(v, t) g[x[u]][x[v]] = g[x[v]][x[u]] = i;
        } else {
            ++kCircle;
            forn(u, t) ens[x[u]].pb(i);
        }
    }
    --k;
    ens.erase(ens.begin(), ens.begin() + 1);
    forn(i, k) {
        assert(ens[i].size() <= 2);
        sort(all(ens[i]));
    }
    ans = false;
    forn(msk, 1 << k) {
        memset(v, 255, sizeof v);
        forn(i, k) {
            if (msk & (1 << i)) up[i] = true; else up[i] = false;
        }
        forn(i, k) {
            forn(j, i) {
                bool cbool = false;
                if ((!up[i] ^ up[j]) && crossDuga(ens[i], ens[j])) cbool = true;
                cross[i][j] = cross[j][i] = cbool;
            }
        }
        if (check()) {
            ans = true;
            return ;
        }
    }
}

void readdata() {
    string X;
    getline(cin, X);
    sscanf(X.c_str(), "%d", &k);
    assert(1 <= k && k <= 13);
    getline(cin, X);
    sscanf(X.c_str(), "%d", &n);
//    assert(1 <= n && n <= 3 * k);
}

int main() {
        freopen(IN_FILE, "rt", stdin);
        freopen(OUT_FILE, "wt", stdout);
        readdata();
        solve();
        outdata();
        return 0;
}

