#include<bits/stdc++.h>
 
#define    pi          acos(-1) 
#define    all(x)      (x).begin(),(x).end()
#define    fill(x,y)   memset(x, y, sizeof(x))
#define    gcd(x,y)    __gcd(x,y)
#define    lcm(x,y)    (x*(y/gcd(x,y))
#define    trace(x)    cout << #x << " = " << x << endl
#define    bug         cout << "Bug check" << endl
#define    endl        '\n'
 
using namespace std; 

int main(){
	//freopen("in.txt","r", stdin);
	//freopen("out.txt","w", stdout);
 
	//ios::sync_with_stdio(0);
	//cin.tie(0);
	int n,m; cin >> n >> m;
	int arr[m]={0};
	bool flg=1;
	map <int,int> ma;
	int p = m;
	while(p--){
		int s,c; cin >> s >> c;
		if(s==1 && c==0){
			flg=0;
		}
		//ss.insert(s);
		auto it=ma.find(s);
		if(it!=ma.end()){
			if(it->second!=c){
				flg=0;
			}
		}
		ma[s]=c;
		arr[s-1]=c;
	}
	if(flg==0){
		cout << "-1" << endl;
		return 0;
	}
	for(int i=0;i<m;i++){
		cout << arr[i];
	}
	cout << endl;
	return 0;
}