#include<iostream>
#include <vector>
#include <map>
using namespace std;

int main() {
	int N, M;
	cin >> N >> M;

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

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

	if (M == 0) {
		if (N == 1) {
			cout << 0 << endl;
		}
		else if (N == 2) {
			cout << 10 << endl;
		}
		else if (N == 3) {
			cout << 100 << endl;
		}
		return 0;
	}

	map<int, int> ans;
	for (int i = 0; i < M; i++) {
		if (ans.count(s.at(i))) {
			if (c.at(i) <= ans.at(s.at(i))) {
				ans[s.at(i)] = c.at(i);
			}
			else continue;
		}
		else {
			ans[s.at(i)] = c.at(i);
		}
	}

	if (N == 1) {
		if (ans.count(1)) {
			cout << ans.at(1) << endl;
			return 0;
		}
		else {
			cout << 0 << endl;
			return 0;
		}
	}

	if (N == 2) {
			if (ans.count(1) == false) {
				ans[i] = 1;
			}
          if (ans.count(2) == false) {
				ans[i] = 0;
		}
	}
  
  if (N == 3) {
			if (ans.count(1) == false) {
				ans[i] = 1;
			}
          if (ans.count(2) == false) {
				ans[i] = 0;
		}
    if (ans.count(3) == false) {
				ans[i] = 0;
		}
	}

	if (ans.at(1) == 0) {
		cout << -1 << endl;
		return 0;
	}
	else {
		for (int i = 1; i <= N; i++) {
			cout << ans.at(i);
		}
	}

	return 0;
}