#include<stdio.h>
#include<math.h>
#include<stack>
#include<string.h>
#include<iostream>
#include<algorithm>
using namespace std;
#define inf 99999999
#define ll long long
#define N 1011
int a[5];
int main()
{
    int n,m;
    while(~scanf("%d %d",&n,&m))
    {
        memset(a,0,sizeof a);
        int flag=0;
        while(m--)
        {
            int x,y;
            scanf("%d %d",&x,&y);
            if(a[x]==0)
            {
                a[x]=y;
            }
            else if(y==a[x])
            {
                continue;
            }
            else
            {
                flag=1;
                continue;
            }
        }
        if(a[1]==0)
            flag=1;
        if(flag)
            printf("-1\n");
        else
        {
            for(int i=1;i<=n;i++)
                printf("%d",a[i]);
            printf("\n");
        }
    }
    return 0;
}
