#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(ll i = 0; i < (n); ++i)
#define repA(i, a, n) for(int  i = a; i <= (n); ++i)
#define all(x) x.begin(), x.end()
#define sz(x) (int) (x).size()
#define fill(a) memset(a, 0, sizeof(a))
#define fst first
#define snd second
#define mp make_pair
#define pb push_back
#define endl '\n'
#define init(n) int n;cin>>n;int a[n];rep(i,n)cin>>a[i];
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<long long, long long> pll;
typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<long long int> vll;
typedef vector<pii> vii;
ll p=1000000007;
# define pi 3.141592
int b,c;
inline double f(double x){
	double v=(x*x+b*x+c)/sin(x);
	return v;
}
ll power(ll a,ll x){
    ll r=1;
    while(x!=0){
        if(x%2==1){
            r=r*a;
        }
        a=a*a;
        x=x/2;
    }
    return r;
}
int main() {
  
    cin.sync_with_stdio(0); cin.tie(0);
    cin.exceptions(cin.failbit);
    int T=1;
    // cin>>T;
    while(T--){
    	int n,m;cin>>n>>m;
    	int a[n]={0};
    	rep(i,3)a[i]=-1;
    	int flag=0;
    	rep(i,m){
    		int s,c;cin>>s>>c;s--;
    		if(a[s]==-1)a[s]=c;
    		else if(c!=a[s]){
    			flag=-1;
    		}
    	}
    	int ans=0;
    	if((a[0]==0&&n!=1)||flag==-1){
    		ans=-1;
    	}
    	else{
    		rep(i,n){
    			int x=a[i];if(x==-1)x=0;
    			// cout<<x<<endl;
    			ans=ans*10+x;
    		}
    	}
    	cout<<ans;
    } 	
    return 0;   
}	