#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll INF = 1e18,MOD = 1e9 + 7;
const int INT_INF = 1e9,INT_MOD=1e9+7;
#define rep(i, N) for(int i = 0; i < N; i++)
typedef pair<int, int> Pi;
typedef pair<double, double> P;
signed main(){
    vector<Pi> sc;
    int n,m;cin>>n>>m;
    int keta[n],l=1;
    for(int i=n-1;i>=0;i--){
        keta[i]=l;
        l*=10;
    }
    rep(i,m){
        int x,y;cin>>x>>y;
        Pi tmp=make_pair(x,y);
        sc.push_back(tmp);
    } 
    sort(sc.begin(),sc.end());
    rep(i,m-1){
        if(sc[i].first==sc[i+1].first and sc[i].second!=sc[i+1].second){
            cout<<"-1"<<endl;
            return 0;
        }
    }
    int ans[n]={};
    rep(i,m){
        if(n>1 and sc[i].first==1 and sc[i].second==0){
            cout<<"-1"<<endl;
            return 0;
        }
        ans[n-sc[i].first]=sc[i].second;
    }
    int p=0;
    rep(i,n){
        p+=ans[i]*keta[n-i-1];
        //cout<<ans[i]<<endl;
        //cout<<p<<endl;
    }
    cout<<p<<endl;
    return 0;
}