#include  <iostream>
#include  <stdio.h>
#include <algorithm>
using namespace std;
#include <vector>
#define rep(i,n) for (int i = 0; i < (n) ; i++)
#define INF 1e9
#define llINF 1e18
#define MOD 1000000007
#define pb push_back
#define ll long long
#define ull unsigned long long
#define vint vector<int>
#define vll vector<ll>

//#include <stack>
//#include <queue>

/*
#include <math.h>
int standerd = int(pow(10.0,9.0)) + 7;
*/
string ans_Yes = "Yes"; 
string ans_No = "No"; 
string ans_yes = "yes"; 
string ans_no = "no"; 
 
ll N;
ll M;

int main(){
    cin >> N >> M;
    int s[M];
    int c[M];
    int keta[N+10]={};
    int keta_max=0;

    bool flag;
    flag=true;
    rep(ni,11){
        keta[ni] =10;
    }
    rep(mi,M){
        cin >> s[mi];
        cin >> c[mi];
        if(keta[s[mi]]<10){
            if(keta[s[mi]]!=c[mi]){

                flag=false;
            }
        }else{
            keta[s[mi]]=c[mi];
            keta_max=max(keta_max,s[mi]);
        }
    }
    if(flag){
        if(keta[keta_max]>0){
            ll value=0;
            for( int ni = 1 ; ni <=N ; ni++ ){
                value=value*10;
                //cout << keta[ni] << endl;
                if(keta[ni]<10){
                    value+=keta[ni];
                }
            }
            cout << value << endl;
        }else{
            cout << -1 << endl;
        }
    }else{
        cout << -1 << endl;
    }


}