/*
本宝的程序外人别想看！！

name: [夏宝宝]
run time：[] ms
compilation time: [] ms
output memory: [] MiB
where: []
state: []
*/
#include<bits/stdc++.h>
using namespace std;

int main()
{
	//freopen(".in", "r", stdin);
	//freopen(".out", "w", stdout);
	
	cout.sync_with_stdio(false);
	ios::sync_with_stdio(0);
	cin.tie(0);
	
	int n, m;
	
	cin>>n>>m;
	
	int s[m+1], c[m+1], a[n+1]={0}; 
	
	for(int i=1; i<=m; i++)
	{
		cin>>s[i]>>c[i];
	}
	
	for(int i=1; i<=m; i++)
	{
		for(int j=i+1; j<=m; j++)
		{
			if(s[i]==s[j] && c[i]!=c[j])
			{
				cout<<"-1"<<endl;
				
				return 0;
			} 
		}
	}
	
	for(int i=1; i<=n; i++)
	{
		a[s[i]]=c[i];
	}
	
	for(int i=1; i<=n; i++)
	{
		if(a[i]==0)
		{
			cout<<"-1"<<endl;
			
			return 0;
		}
		else
		{
			break;
		}
	}
	
	for(int i=1; i<=n; i++)
	{
		cout<<a[i];
	}
	
	cout<<endl;
	
	return 0;
}
