Moriarty has trapped n people in n distinct rooms in a hotel. Some rooms are locked, others are unlocked. But, there is a condition that the people in the hotel can only escape when all the doors are unlocked at the same time. There are m switches. Each switch control doors of some rooms, but each door is controlled by exactly two switches.

You are given the initial configuration of the doors. Toggling any switch, that is, turning it ON when it is OFF, or turning it OFF when it is ON, toggles the condition of the doors that this switch controls. Say, we toggled switch 1, which was connected to room 1, 2 and 3 which were respectively locked, unlocked and unlocked. Then, after toggling the switch, they become unlocked, locked and locked.

You need to tell Sherlock, if there exists a way to unlock all doors at the same time.

Input

First line of input contains two integers n and m (2 ≤ n ≤ 105, 2 ≤ m ≤ 105) — the number of rooms and the number of switches.

Next line contains n space-separated integers r1, r2, ..., rn (0 ≤ ri ≤ 1) which tell the status of room doors. The i-th room is locked if ri = 0, otherwise it is unlocked.

The i-th of next m lines contains an integer xi (0 ≤ xi ≤ n) followed by xi distinct integers separated by space, denoting the number of rooms controlled by the i-th switch followed by the room numbers that this switch controls. It is guaranteed that the room numbers are in the range from 1 to n. It is guaranteed that each door is controlled by exactly two switches.

Output

Output "YES" without quotes, if it is possible to open all doors at the same time, otherwise output "NO" without quotes.

Examples

Input

3 3
1 0 1
2 1 3
2 1 2
2 2 3


Output

NO

Input

3 3
1 0 1
3 1 2 3
1 2
2 1 3


Output

YES

Input

3 3
1 0 1
3 1 2 3
2 1 2
1 3


Output

NO

Note

In the second example input, the initial statuses of the doors are [1, 0, 1] (0 means locked, 1 — unlocked).

After toggling switch 3, we get [0, 0, 0] that means all doors are locked.

Then, after toggling switch 1, we get [1, 1, 1] that means all doors are unlocked.

It can be seen that for the first and for the third example inputs it is not possible to make all doors unlocked.
#include <bits/stdc++.h>
using namespace std;
namespace graphs {
template <typename T>
class graph_t {
 public:
  struct edge_t {
    int32_t from;
    int32_t to;
    T dist;
  };
  const int32_t n;
  std::vector<edge_t> edges;
  std::vector<std::vector<int32_t>> g;
  void add_directed_edge(const int32_t from, const int32_t to) {
    assert(0 <= from and from < n);
    assert(0 <= to and to < n);
    g[from].push_back(edges.size());
    edges.push_back({from, to, T()});
  }
  void add_directed_edge(const int32_t from, const int32_t to, const T dist) {
    assert(0 <= from and from < n);
    assert(0 <= to and to < n);
    g[from].push_back(edges.size());
    edges.push_back({from, to, dist});
  }
  void add_undirected_edge(const int32_t from, const int32_t to) {
    add_directed_edge(from, to);
    add_directed_edge(to, from);
  }
  void add_undirected_edge(const int32_t from, const int32_t to, const T dist) {
    add_directed_edge(from, to, dist);
    add_directed_edge(to, from, dist);
  }
  graph_t(int32_t n) : n(n), g(n){};
  friend std::string to_string(const edge_t &e) {
    return "(" + to_string(e.from) + " -> " + to_string(e.to) + ")";
  }
};
template <typename T>
std::string to_string(const graph_t<T> &g) {
  auto to_string_list = [&g](const std::vector<int32_t> &adj) {
    std::string res = "{";
    bool first = true;
    for (auto e : adj) {
      if (!first) {
        res += ", ";
      }
      res += to_string(g.edges[e]);
      first = false;
    }
    res += "}";
    return res;
  };
  std::string res = "{";
  bool first = true;
  for (const auto &adj : g.g) {
    if (!first) {
      res += ", ";
    }
    res += to_string_list(adj);
    first = false;
  }
  res += "}";
  return res;
}
template <typename T>
std::vector<std::vector<int32_t>> tarjan_scc(const graph_t<T> &g) {
  std::vector<std::vector<int32_t>> scc;
  std::vector<int32_t> index(2 * g.g.size(), -1);
  std::vector<int32_t> low(2 * g.g.size());
  std::vector<int32_t> s;
  std::vector<bool> on_stack(2 * g.g.size(), false);
  int32_t counter = 0;
  std::function<void(int32_t)> calc_scc = [&](int32_t v) {
    index[v] = counter;
    low[v] = counter++;
    on_stack[v] = true;
    s.push_back(v);
    for (auto e : g.g[v]) {
      auto to = g.edges[e].to;
      if (index[to] == -1) {
        calc_scc(to);
        low[v] = std::min(low[to], low[v]);
      } else if (on_stack[to]) {
        low[v] = std::min(index[to], low[v]);
      }
    }
    if (low[v] == index[v]) {
      scc.push_back({});
      do {
        scc.back().push_back(s.back());
        on_stack[s.back()] = false;
        s.pop_back();
      } while (on_stack[v]);
    }
  };
  for (int32_t v = 0; v < g.n; v++) {
    if (index[v] == -1) {
      calc_scc(v);
    }
  }
  return scc;
};
}  // namespace graphs
namespace twosat {
class twosat {
  const int32_t n;
  graphs::graph_t<bool> g;
  inline int32_t normalize(int32_t x) const {
    assert(1 <= abs(x) and abs(x) <= n);
    return x > 0 ? x - 1 : -x - 1 + n;
  }
  inline int32_t negate(int32_t norm_x) const {
    assert(0 <= norm_x and norm_x < 2 * n);
    return norm_x < n ? norm_x + n : norm_x - n;
  }

 public:
  std::vector<bool> solution;
  twosat(int32_t n) : n(n), g(2 * n), solution(n, false) { assert(n > 0); }
  void imply(int32_t x, int32_t y) {
    assert(1 <= abs(x) and abs(x) <= n);
    assert(1 <= abs(y) and abs(y) <= n);
    g.add_undirected_edge(normalize(x), normalize(y));
  }
  bool satisfy() {
    auto scc = graphs::tarjan_scc<bool>(g);
    std::vector<int32_t> vscc(2 * n);
    for (auto scc_index = 0; scc_index < (int32_t)scc.size(); scc_index++) {
      for (const auto &v : scc[scc_index]) {
        vscc[v] = scc_index;
      }
    }
    for (auto v = 0; v < n; v++) {
      if (vscc[v] == vscc[negate(v)]) {
        return false;
      }
      solution[v] = (vscc[v] < vscc[negate(v)]);
    }
    return true;
  }
};
}  // namespace twosat
int32_t main() {
  int n, m;
  cin >> n >> m;
  vector<bool> r(n, false);
  for (auto i = 0; i < n; i++) {
    int x;
    cin >> x;
    r[i] = !!x;
  }
  vector<vector<int>> switches(n);
  for (int i = 0; i < m; i++) {
    int cnt;
    cin >> cnt;
    for (int j = 0; j < cnt; j++) {
      int x;
      cin >> x;
      switches[x - 1].push_back(i);
    }
  }
  twosat::twosat sat(m);
  for (int i = 0; i < n; i++) {
    assert(switches[i].size() == 2);
    const int x = switches[i][0] + 1;
    const int y = switches[i][1] + 1;
    if (r[i]) {
      sat.imply(-x, -y);
      sat.imply(x, y);
    } else {
      sat.imply(x, -y);
      sat.imply(y, -x);
    }
  }
  cout << (sat.satisfy() ? "YES" : "NO") << "\n";
}
