#include <iostream>

int main()
{
	int N;
	int M;
	int* s;
	int* c;
	int ans=0;

	std::cin >> N >> M;

	s = new int[M];
	c = new int[M];

	for (int i = 0; i < M; i++)
	{
		std::cin >> s[i] >> c[i];
	}

	bool a;
	for (int i = 0; i < M; i++)
	{
		a = true;
		if(s[i]==1&&c[i]==0)
		{
			if (N == 1 && M <= 1) {
				ans = 0;
				goto out;
			}
			else 
			{
				ans = -1;
				goto out;
			}
		}

		for (int j = 0; j < M; j++) 
		{
			if (s[i] == s[j] && c[j] != c[j])
			{
				ans = -1;
				goto out;
			}
			else#include <iostream>

int main()
{
	int N;
	int M;
	int* s;
	int* c;
	int ans=0;

	std::cin >> N >> M;

	s = new int[M];
	c = new int[M];

	for (int i = 0; i < M; i++)
	{
		std::cin >> s[i] >> c[i];
	}

	bool a;
	for (int i = 0; i < M; i++)
	{
		a = true;
		if(s[i]==1&&c[i]==0)
		{
			if (N == 1 && M <= 1) {
				ans = 0;
				goto out;
			}
			else 
			{
				ans = -1;
				goto out;
			}
		}

		for (int j = 0; j < M; j++) 
		{
			if (s[i] == s[j] && c[j] != c[j])
			{
				ans = -1;
				goto out;
			}
			else if(s[i] == s[j] && c[j] == c[j]&&i<j)
			{
				ans += (int)std::pow(10, N - s[i]) * c[i];
				a = false;
				break;
			}
		}
		if(a)
			ans += (int)std::pow(10, N - s[i]) * c[i];
	}

out:
	std::cout << ans;

	return 0;
} if(s[i] == s[j] && c[j] == c[j]&&i<j)
			{
				ans += (int)std::pow(10, N - s[i]) * c[i];
				a = false;
				break;
			}
		}
		if(a)
			ans += (int)std::pow(10, N - s[i]) * c[i];
	}

out:
	std::cout << ans;

	return 0;
}