#include <iostream>
#include <string>
using namespace std;

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