#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) repi(i,0,n)
#define rrepi(i,a,b) for(int i=int(a);i>int(b);--i)
#define ALL(x) (x).begin(),(x).end()

int n, m;
string s;

void main() {
	char s;
	cin >> n >> m;
	string ans = "0";
	rep(i, n - 1)ans += "0";
	vector<bool> f(n, false);
	rep(i, m) {
		cin >> k >> s;
		k--;
		if (f[k] == 0) {
			ans[k] = s;
			f[k] = 1;
		}
		else {
			if (ans[k] == s)continue;
			else {
				cout << -1;
				return;
			}
		}
	}

	if (n > 1 && f[0] == true && ans[0] == '0') {
		ans = "-1";
		cout << ans;
		return;
	}
	else if (n > 1 && f[0] == false && ans[0] == '0')ans[0] = '1';
	cout << stoi(ans);
}

