#include<bits/stdc++.h>
using namespace std;

#define ll long long
#define mtv(kit) cout<<#kit<<" - "<<kit<<"\n";
#define ff first
#define ss second
#define pb push_back
#define rep(i,a,b) for(i=a;i<b;i++)
#define pii pair<ll , ll>
#define all(x) x.begin(),x.end()
#define nl "\n"
#define ump unordered_map

void doit(){
    ll n,q,i,a1 = 0, a2 = 0;
    ump<ll, ll>mpAC,mpWA;
    string s;
    cin >> n >> q;
    while(q--){
        ll k;
        cin >> k >> s;
        if(s == "WA"){
            if(mpAC.find(k) == mpAC.end())mpWA[k]++;
        }
        else {
            if(mpAC.find(k) == mpAC.end()){
                a2 += mpWA[k];
                a1++;
            }
            mpAC[k] = 1;
        }
    }
    cout << a1 << " " << a2 << nl;
}

int main() {
#ifndef ONLINE_JUDGE
    freopen("input1.txt","r",stdin);
    freopen("output1.txt","w",stdout);
#endif
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll t = 1;
    // cin >> t;
    for(ll i = 1; i <= t; i++){
        doit();
    }
}

#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
#define all(x) x.begin(),x.end()
#define rep(i,j,n) for (long long i = j; i < (long long)(n); i++)
#define _GLIBCXX_DEBUG
const ll MOD = 1000000007;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
//(a+b-1)/b
//priority_queue<ll, vector<ll>, greater<ll>> q;

signed main(){
	ll n,m; cin>>n>>m;
	vl a(m);
	vector<char> b(m);
	ll ans=-1;
	rep(i,0,m){
		cin>>a[i]>>b[i];
	}
	rep(i,0,1000){
		string s=to_string(i);
		if(s.size()!=n)continue;
		bool ok=true;
		rep(i,0,m){
			if(s[a[i]-1]!=b[i])ok=0;
		}
		if(ok){
			ans=i;
			break;
		}
	}
	cout << ans << endl;

	return 0;
}