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

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