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

ll pow(ll a, int n) {
	ll tmp = 1;
	while (n) {
		tmp *= a;
		n--;
	}
	return tmp;
}

int main() {
	int n, m;
	cin >> n >> m;
	vector<bool> first(n, true);
	vector<int> keta(n, 0);
	for (int i = 0; i < m; i++) {
		int s, c;
		cin >> s >> c;
		if (s == 1 && c == 0) {
			cout << -1 << endl;
			return 0;
		}
		s--;
		if (!first.at(s)) {
			if (c != keta.at(s)) {
				cout << -1 << endl;
				return 0;
			}
		}
		else if (first.at(s)) {
			keta.at(s)= c;
			first.at(s) = false;
		}
	}
	int ans = 0;
	if (first.at(0)) ans += pow(10, n - i - 1);
	for (int i = 0; i < n; i++) {
		if (!first.at(i)) {
			ans += keta.at(i)*pow(10, n - i - 1);
		}
	}
	cout << ans << endl;
}
