#include <iostream>
#include <vector>
#include <string>
#include <utility>

using namespace std;

int main() {
	int n, m; cin >> n >> m;
	vector<pair<int, char> > sc(m);
	for (auto& a : sc) {
		cin >> a.first >> a.second;
		--a.first;
	}
	for (int i = 0; i < 1000; ++i) {
		string x = to_string(i);
		if (x.size() != n) continue;
		int j;
		for (j = 0; j < m; ++j)
			if (x[sc[j].first] != sc[j].second) break;
		if (j == m) {
			cout << i << endl;
			return 0;
		}
	}
	cout << -1 << endl;

	return 0;
}