#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)
#define all(x) (x).begin(),(x).end()
using ll = long long;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }



int main() {
	
	cin.tie(0);
	ios::sync_with_stdio(false);
	
	
	int n, m; cin >> n >> m;
	
	if(n == 1 && m == 0){
		cout << 0 < endl;
		return 0;
	}
	
	//cout << n << m << endl;
	
	vector<int> s(m), c(m);
	rep(i,m) cin >> s[i] >> c[i];
	
	//rep(i,m) cout <<  s[i] << c[i] << endl;
	
	
	vector<int> a(n);
	rep(i, n) a[i] = -1;
	
	rep(i, m){
		int j = s[i] - 1;
		int value = c[i];
		if(a[j] == -1){
			a[j] = value;
			//cout << "test1" << endl;
		}
		else if(a[j] != value){
			cout << "-1" << endl;
			return 0;
		}
		//else cout << "test2" << endl;
	}
	if (n >= 2 && a[0] == 0){
		cout << "-1" << endl;
		return 0;
	}
	
	//cout << a[0] << endl;
	
	rep(i, n) {
		if(i == 0 && a[i] == -1) cout << 1;
		else if(a[i] == -1) cout << 0;
		else cout << a[i];
		
		//cout << "test3" << endl;
	}
	cout << endl;
	
	
//	sort(all(a));

	return 0;
}
