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


int main(){
    ios::sync_with_stdio(0);
    cin.tie(0);

    int n, m;
    cin>>n>>m;
    pait<int, int> p[m];
    loop(m){
        cin>>p[i].first>>p[i].second;
    }

    string s;
    bool ok = 1;
    int r, q;
    for(int j = 0; j<1000; j++){
        ok = 1;
        s = to_string(j);
        if(s.size() != n) continue;

        loop(m){
            r = p[i].first - 1;
            q = p[i].second;
            if(s[r] != '0'+q){
                ok = false;
            }
        }

        if(ok){
            cout<<j<<"\n";
            return 0;
        }
    }
    cout<<-1<<"\n";
    return 0;
}