void ABC157C()
{
	int N, M;
	cin >> N >> M;
	vi A(N, -1);
	for (int i = 0; i < M; ++i)
	{
		int s, c;
		cin >> s >> c;
		--s;
		if (A[s] > -1 && A[s] != c)
		{
			cout << "-1" << endl;
			return;
		}
		A[s] = c;
	}
	if (N > 1 && A[0] == 0)
	{
		cout << "-1" << endl;
		return;
	}
	if (A[0] == -1)
		A[0] = 1;
	int ans = 0;
	for (int i = 0; i < N; ++i)
	{
		ans *= 10;
		ans += max(A[i],0);
	}
	cout << ans << endl;

}

int main()
{
	ABC157C();
	return 0;
}