// Michael Pfeifer
// Version 04, 2018/02/17

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;

typedef long long ll;
typedef long double ld;
typedef unsigned int uint;
typedef unsigned long long ull;

const ld  pi   = 4.0*atanl(1.0);
const int iinf = 1e9 + 10;
const ll  inf  = 1e18 + iinf + 10;
const int mod  = 1000000007;
const ld  prec = .000001;

#define enld endl
#define pb push_back
#define debug(x) cout<<#x<<" -> "<<x<<'\n'
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define uni(x) (x).erase(unique(all(x)), (x).end())
#define rep(i, n) for (ll i = 0; i < (ll)(n); ++i)
#define rep1(i, n) for (ll i = 1; i <= (ll)(n); ++i)
#define umap unordered_map
#define uset unordered_set

template<class TIn>
using indexed_set = tree<
        TIn, null_type, less<TIn>,
        rb_tree_tag, tree_order_statistics_node_update>;

void fast() {
    ios::sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);
}

void file() {
    auto a = freopen("a.in",  "r", stdin);
    auto b = freopen("a.out", "w", stdout);
    if(!a || !b) cout << "uh oh" << endl;
}





vector<vector<int>> adj;
string s;

int find(vector<int>& d, int a) {
    if(d[a] == -1) return a;
    return d[a] = find(d, d[a]);
}

void join(vector<int>& d, int a, int b) {
    a = find(d,a);
    b = find(d,b);
    if(a == b) return;
    d[a] = b;
}

int main() {
    //file();
    //fast();

    int n, m;
    cin >> n >> m;
    string s;
    cin >> s;

    vector<bool> touchesa(n, false);
    vector<bool> touchesb(n, false);

    vector<pair<int,int>> edges;
    vector<bool> selfloop(n,false);

    for(int i = 0; i < m; i++) {
        int n1, n2;
        cin >> n1 >> n2;
        n1--; n2--;

        edges.pb({n1,n2});
        if(n1 == n2) {
            selfloop[n1] = true;
        }

        if(s[n2] == 'A') {
            touchesa[n1] = true;
        }
        else {
            touchesb[n1] = true;
        }

        if(s[n1] == 'A') {
            touchesa[n2] = true;
        }
        else {
            touchesb[n2] = true;
        }
    }

    bool works = false;
    vector<int> d(n, -1);
    for(auto i : edges) {
        if(selfloop[i.first] && selfloop[i.second]) {
            works = true;
        }
        if(touchesa[i.first] && touchesa[i.second] &&
           touchesb[i.first] && touchesb[i.second]) {
            if(i.first != i.second && find(d,i.first) == find(d,i.second)) {
                works = true;
            }
            join(d,i.first, i.second);
        }
    }

    if(works) {
        cout << "Yes" << endl;
    }
    else {
        cout << "No" << endl;
    }

    return 0;
}