#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

int main() {

	int n, m; cin >> n >> m;
	string ans = "";
	for (int i = 0; i < n; i++) {
		ans += 'x';
	}
	for (int i = 0; i < m; i++) {
		int s; char c; cin >> s >> c;
		s--;
		if (ans[s] != 'x' && ans[s] != c) {
			ans = "-1";
			break;
		}
		else {
			ans[s] = c;
		}
	}
	for (int i = 0; i < n; i++) {
		if (ans[i] == 'x') ans[i] = '0';
	}
	if (ans[0] == '0') ans = "-1";
	cout << ans << endl;
    return 0;
}