int main() {
	int n, m, i, x[3] = { 10,10,10 }, c, s;
	cin >> n >> m;
	if (n == 1) {
		for (i = 0; i < m; i++) {
			cin >> s >> c;
			if (x[0] != 10 && x[0] != c) {
				cout << "-1";
				return 0;
			}
			if (s == 1 && c == 0) {
				cout << "-1";
				return 0;
			}
			else x[0] = c;
		}
		cout << x[0];
		return 0;
	}
	if (n == 2) {
		for (i = 0; i < m; i++) {
			cin >> s >> c;
			if (x[s-1] != 10 && x[s-1] != c) {
				cout << "-1";
				return 0;
			}
			if (s==1&&c==0) {
				cout << "-1";
				return 0;
			}
			else x[s-1] = c;
		}
		if (x[0] == 10)x[0] = 1;
		if (x[1] == 10)x[1] = 0;
		cout << x[0] << x[1];
	}
	if (n == 3) {
		for (i = 0; i < m; i++) {
			cin >> s >> c;
			if (x[s - 1] != 10 && x[s - 1] != c) {
				cout << "-1";
				return 0;
			}
			if (s == 1 && c == 0) {
				cout << "-1";
				return 0;
			}
			else x[s - 1] = c;
		}
		if (x[0] == 10)x[0] = 1;
		if (x[1] == 10)x[1] = 0;
		if (x[2] == 10)x[2] = 0;
		cout << x[0] << x[1]<<x[2];
	}
}