#include <bits/stdc++.h>

using namespace std;


#define PI 3.14159265
#define int long long


int sqr(int x){
	return x * x;
}


main(){

	int n, m; cin >> n >> m;


	vector <int> s(m), c(m);

	for(int i = 0; i < m; i++){
		cin >> s[i] >> c[i];
	}

	string ans;

	for(int i = 0; i < n; i++) ans.push_back(false);

	for(int i = 0; i < m; i++){
		if(s[i] == 1 and c[i] == 0){
			if(n == 1)
				cout << 0 << endl;
			else{
				cout << -1 << endl; return 0;
			}
		}else{
			if(ans[s[i] - 1] == false){
				ans[s[i] - 1] = c[i] + '0';
			}else{
				if((ans[s[i] - 1] - '0') != c[i]){
					// cout << ans << endl;
					// cout << c[i] << endl;
					// cout << ans[s[i] - 1] << endl;
					cout << -1 << endl; return 0;
				}
			}
		}
	}

	for(char c : ans){
		if(c)
			cout << c;
		else
			cout << '0';
	}
	cout << endl;
	
	
	
	return 0;
}