#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<string>
#include<cmath>
#include<map>
#include<stack>
#include<vector>
#include<queue>
#include<set>
#include<algorithm>
#define INF 0x3f3f3f3f
#define mod 1000000009
#define e  2.718281828459045
#define eps 1.0e18
#define PI acos(-1)
#define lowbit(x) (x&(-x))
#define memset(x,y) memset(x,y,sizeof(x))
#define lson i << 1,l,m
#define rson i << 1 | 1,m + 1,r
#define ll long long
using namespace std;
int a[N];
bool vis[N];

int main()
{
    int n,m,pos,val;
	scanf("%d%d",&n,&m);
	
	bool f = 0;
	for(int i = 1;i <= m;++i){
		scanf("%d%d",&pos,&val);
		if(vis[pos]){
			if(val != a[pos]) f = 1;
			continue;
		}
		vis[pos] = 1;
		a[pos] = val;
	}
	if(f) printf("-1\n");
	else{
		if(n == 1) printf("%d",a[1]);
		else{
			if(!vis[1]) a[1] = 1;
			if(!a[1]) printf("-1\n");
			else{
				for(int i = 1;i <= n;++i) printf("%d",a[i]);
			}
		}
	}
    return 0;
}

