#include <bits/stdc++.h>
using namespace std;
#define SPEED ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define ll unsigned long long
#define ld long double
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define eb emplace_back
const int mod = 1e9 + 7;
int main()
{
	SPEED
	int n,m;
	cin >> n >> m;
	string str = "";
	for (int i = 0; i < n; ++i)
	{
		str+="0";
	}

	int s;char c;
	int mark[n] = {0};
	char no[n];
	for (int i = 0; i < m; ++i)
	{
		cin >> s >> c;
		s--;
		if (mark[s] && no[s]!=c)
		{
			cout << -1;
			return 0;
		}
		else
		{
			mark[s] = 1;
			no[s] = c;
			str[s] = c;

		}
	}

	if (str[0] == '0')
	{
		cout << -1;
	}
	else
	{
		cout << str;
	}
	return 0;
}