#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
 
const int maxV = 90010;
const int maxN = 3e2+10;
const int inf = 0x3f3f3f3f;
const ll MOD = 1e9+7;
const ll INF = 1000000000000000010LL;
#define X first
#define Y second


int a[maxN][maxN];
int c[maxN][maxN];
int b[maxN];
int d[maxN];
int main() {
	int n,m;
	scanf("%d%d",&n,&m);
	for(int i=1;i<=n;i++)
	{
		d[i] = -1;
	}
	for(int i=1;i<=m;i++)
	{
		int x,y;
		scanf("%d%d",&x,&y);
		if(d[x] == -1)
			d[x] = y;
		else if(d[x] != y)
		{
			puts("-1");
			return 0;
		}
	}
	if(d[1] == -1)
	{
		d[1] = 1;
	}
	else if(d[1] == 0)
	{
		puts("-1");
		return 0;
	}
	for(int i=1;i<=n;i++)
	{
		if(d[i] == -1)
			d[i] = 0;
	}
	int ans = 0;
	for(int i=1;i<=n;i++)
	{
		ans = ans*10 + d[i];
	}
	cout<<ans<<endl;
	return 0;
}