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

int main(){
    int n, m;
    cin >> n >> m;
    int num[n]={0};
    int s[m], c[m];
    rep(i, m) cin >> s[i] >> c[i];

    bool b=true;
    rep(i, m){
        if(num[s[i]-1]==0) num[s[i]-1]=c[i];
        else b=false;
    }

    if(num[0]==0) b=false;
    if(!(b)){
        cout<<-1<<endl;
        return 0;
    }
    rep(i, n){
        cout<<num[i];
    }
    cout<<endl;
    return 0;
}