#include "bits/stdc++.h"
using namespace std;


int main() {

	int N, M;
	cin >> N >> M;

	vector<int> s(M);
	vector<int> c(M);
	vector<int> ans(M);

	int anser = 0;

	for (int i = 0;i < M;i++) {
		cin >> s.at(i) >> c.at(i);
		if (ans.at(s.at(i) - 1) == 0) {
			ans.at(s.at(i) - 1) = c.at(i);
		}
	}

	bool can = true;
	for (int i = 0;i < M-1;i++) {
		for (int j = i+1;j < M;j++) {
			if (s.at(i) == s.at(j) && c.at(i) != c.at(j)) {
				can = false;
				break;
			}
		}
		if (!can)
			break;
	}
	if (!can || (N >= 2 && ans.at(0) == 0))
		cout << -1;

	else {
		for (int i = 0;i < M;i++) {
			anser += pow(10, N - 1 - i) * ans.at(i);
		}
		cout << anser;
	}