#include<iostream>
#include<string>
#include<vector>
#include <map>
#include <utility>
#include<memory>
#include <algorithm>

using namespace std;

int main() {
	int n, m;
	cin >> n >> m;
	multimap<int, int> s;
	unique_ptr<int[]> answer = make_unique<int[]>(3);

	for (int var = 0; var < m; ++var) {
		int s1, s2;
		cin >> s1 >> s2;
		s.emplace(s1, s2);

		if(s1 == 1 && s2 == 0){
			cout << -1 << endl;
			return 0;
		}

		auto p = s.equal_range(s1);
		for (auto it = p.first; it != p.second; ++it) {
			if (s2 != it->second) {
				cout << -1 << endl;
				return 0;
			}
		}
	}

	for (auto &num : s) {
		answer[(num.first) - 1] = num.second;
	}

	cout << 100 * answer[0] + 10 * answer[1] + answer[2] << endl;

	return 0;
}
