#include using namespace std; #define rep(i, j, n) for(int i=j;i pi; template using vt = vector; template using vvt = vector>; i64 gcd(i64 n, i64 m) {return (m == 0? n : gcd(m, n % m));} i64 lcm(i64 n, i64 m) {return (n / gcd(n, m) * m);} int dx[] = {0, 1, 0, -1}; int dy[] = {1, 0, -1, 0}; int n, m; vt a; vvt edge; int num[3]; bool ok = false; void dfs(int i, int v) { if(ok) return; num[i] = a[v]; if(i == 2) { if(num[0] != num[1] && num[1] != num[2] && num[2] != num[0]) { ok = true; } return; } for(auto nxt : edge[v]) { dfs(i + 1, nxt); } } int main() { cin.tie(0); ios::sync_with_stdio(false); cin >> n >> m; a.resize(n); rep(i, 0, n) cin >> a[i]; edge.resize(n); rep(i, 0, m) { int u, v; cin >> u >> v; u--; v--; edge[u].push_back(v); edge[v].push_back(u); } rep(i, 0, n) dfs(0, i); if(ok) cout <<"YES\n"; else cout << "NO\n"; }