#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (n); i++)
using ll = long long;
using namespace std;
using P = pair<int,int>;

int main(){
    int n,m;
    cin >> n >> m;
    vector<P> p(m);
    for(int i = 0; i < m; i++){
        cin >> p[i].first >> p[i].second;
    }
    for(int x = 0; x < 1000; i++){
        int keta = 1;
        int nx = n/10;
        vector<int> d(1,x%10);
        while(nx){
            keta++;
            d.push_back(nx%10);
            nx /= 10;
        }
        if(keta != n) continue;
        bool ok = true;
        reverse(d.begin(), d.end());
        for(int i = 0; i < m; i++){
            if(d[p[i].first - 1] != p[i].second) ok = false;
        }
        if(ok){
            cout << x << endl;
            return 0;
        }
    }
    cout << -1 << endl;
    return 0;
}