#include <bits/stdc++.h>
using namespace std;
using ll = long long int;
using ipair = pair<int,int>;
#define rep(i,a,b) for(int (i)=a;(i)<(int)(b);(i)++)
    
int main(){
    int N,M;
    cin >> N >> M;
    vector<ipair> pa(M);
    rep(i,0,M) cin>>pa[i].first >> pa[i].second;
    sort(pa.begin(), pa.end(), 
     [](const ipair& x, const ipair& y) { return x.first > y.first;});
    
    int ans = 0;
    int fin_flag = 0;
    
    rep(i,0,M){
        if(i<M-1&&pa[i].first==pa[i+1].first&&pa[i].second != pa[i+1].second){
            fin_flag = 1;
            break;
        }
        else{
            if(pa[i].first==1 && pa[i].second==0){
                fin_flag = 1;
                break;
        }
    }
    if(fin_flag==1) cout << "-1" << endl;
    else{
        ans += pa[0].second*pow(10,N-pa[0].first);
        rep(i,1,M){
            if(pa[i].first != pa[i-1].first){
                ans += pa[i].second*pow(10,N-pa[i].first);
            }
        }
        if(ans/pow(10,N-1)<=0) ans += pow(10,N-1);
        cout << ans << endl;
    }   
}