#include <iostream>
#include <bitset>
#include <iomanip>
#include <string>
#include <vector>
#include <cmath>
#include <queue>
#include <algorithm>

using namespace std;

int main()
{
	string buf="000";
	long long n, m;
	bool flag = true;

	cin >> n >> m;

	vector<vector<long long>> s(m,vector<long long>(2));

	for (long long i = 0; i < m; i++)
		cin >> s[i][0] >> s[i][1];

	sort(s.begin(), s.end());

	for (long long i = 0; i < s.size() - 1; i++)
		if (s[i][0] == s[i + 1][0] && s[i][1] == s[i + 1][1])
			s.erase(s.begin() + i);

	if (s.size() == 1)
	{
		if (s[0][0] == 1 && s[0][1] == 0)
			flag = false;
	}
	else
	{
		for (long long i = 0; i < s.size() - 1; i++)
		{
			if (s[i][0] == s[i + 1][0] && s[i][1] == s[i + 1][1])
				continue;
			else if ((s[i][0] == s[i + 1][0]) || (s[i][0] == 1 && s[i][1] == 0))
				flag = false;
		}
	}

	if (flag)
	{
		for (long long i = 0; i < s.size(); i++)
		{
			buf[s[i][0]-1] = s[i][1]+'0';
		}

		char ans[3];

		for (long long i = 0; i < n; i++)
			ans[i] = buf[i];

		cout << atoi(ans) << endl;
	}
	else
		cout << "-1" << endl;
}