#include<algorithm>
#include<cmath>
#include<iomanip>
#include<iostream>
#include<map>
#include<numeric>
#include<queue>
#include<set>
#include<sstream>
#include<unordered_map>
#include<unordered_set>
#include<vector>
#include<random>
#include<sys/time.h>
using ll = long long;
enum : int { M = (int)1e9 + 7 };
enum : ll { MLL = (ll)1e18L + 9 };
using namespace std;
#ifdef LOCAL
#include"rprint2.hpp"
#include"debug_deque.hpp"
#define vector DebugDeque
#else
#define FUNC(name) template <ostream& out = cout, class... T> void name(T&&...){ }
FUNC(prints) FUNC(printe) FUNC(printw) FUNC(printew) FUNC(printb) FUNC(printd) FUNC(printde) FUNC(printdu);
#endif
template <class S, class T>
istream& operator >> (istream& in, pair<S, T>& p){ return in >> p.first >> p.second; }
template <class T>
istream& operator >> (istream& in, vector<T>& v){ for(auto& e : v){ in >> e; } return in; }

timeval start;
double elapsed(){
    timeval now;
    gettimeofday(&now, nullptr);
    return (now.tv_sec - start.tv_sec) + (now.tv_usec - start.tv_usec) / 1e6;
}

struct Graph{
    struct Node{
        char c;
        int s = 0, d = 0;
        unordered_set<int> dests;
    };
    vector<Node> nodes;
    Graph(int num): nodes(num){ }
    int id(Node* n){ return n - &nodes[0]; }
    int id(Node& n){ return &n - &nodes[0]; }
    void print(){ for(auto& node : nodes){ prints(id(node), node.dests); } }
    void addEdge(int from, int dest){
        nodes[from].dests.insert(dest);
    }
    void addEdge2(int from, int dest){
        addEdge(from, dest);
        addEdge(dest, from);
    }
    void init(int idx){
        for(int didx : nodes[idx].dests){
            nodes[idx].s += nodes[idx].c == nodes[didx].c;
            nodes[idx].d += nodes[idx].c != nodes[didx].c;
        }
    }
    bool bad(int idx){
        // printd(idx, nodes[idx].s, nodes[idx].d);
        return !nodes[idx].s || !nodes[idx].d;
    }
    void erase(int idx, unordered_set<int>& nextBads, unordered_set<int>& allBads){
        for(int didx : nodes[idx].dests){
            if(idx != didx){
                nodes[didx].s -= nodes[didx].c == nodes[idx].c;
                nodes[didx].d -= nodes[didx].c != nodes[idx].c;
                if(!allBads.count(didx) && bad(didx)){
                    nextBads.insert(didx);
                }
                nodes[didx].dests.erase(idx);
            }
        }
        nodes[idx].dests.clear();
    }
};

int main(){
    gettimeofday(&start, nullptr);
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n, m;
    cin >> n >> m;
    Graph g(n);
    for(int i = 0; i < n; i++){
        char c; cin >> c;
        g.nodes[i].c = c;
    }
    for(int i = 0; i < m; i++){
        int a, b;
        cin >> a >> b;
        a--; b--;
        g.addEdge2(a, b);
    }
    for(int i = 0; i < n; i++){
        g.init(i);
    }
    // g.print();

    unordered_set<int> bads;
    for(int i = 0; i < n; i++){
        if(g.bad(i)){
            bads.insert(i);
        }
    }
    // iota(cands.begin(), cands.end(), 0);
    unordered_set<int> allBads;
    allBads.reserve(n);
    int cnt = 0;
    while(1){
        if(bads.empty()){ break; }
        unordered_set<int> nextBads;
        allBads.insert(bads.begin(), bads.end());
        for(auto i : bads){
            g.erase(i, nextBads, allBads);
        }
        if((cnt & 0xff) == 0xff && elapsed() > 1.9){ return 1; }
        bads.swap(nextBads);
        cnt++;
    }
    // |v| == 1
    // g.print();
    cout << ((int)allBads.size() != n ? "Yes" : "No") << '\n';
}


Measured memory_bytes: 43556