#include<stdio.h>
#include<stdbool.h>

int main(void){
    int n,m;
    bool flag = true;
    int count1;
    int count2;
    int count3;
    scanf("%d %d",&n,&m);
    const int y ;
    int a[3]={-1,-1,-1};

    for(int i=0;i<m;++i){
        int s,c,x=-1,y=-1,z=-1;
        scanf("%d %d",&s,&c);
        if(s == 1){
            if(a[0]!=c){
                count1++;
            }
            a[0] = c;
        }else if(s == 2){
            if(a[1]!=c){
                count2++;
            }
            a[1] = c;
        }else{
            if(a[2]!=c){
                count3++;
            }
            a[2] = c;
        }
    }

    if(count1 == 0){
        a[0] = 0;
    }
    if(count2 == 0){
        a[1] = 0;
    }
    if(count3 == 0){
        a[2] = 0;
    }

    if(count1>1 || count2>1 || count3>1){
        printf("%d",-1);
        return 0;
    }

    if(count1!=0 && a[0]==0){
        printf("%d",-1);
        return 0;
    }
    if(count1 == 0){
        printf("%d",-1);
        return 0;
    }

    if(n==1){
        printf("%d",a[0]);
    }else if(n==2){
        if(count2!=0){
            printf("%d%d",a[0],a[1]);
        }else{
            printf("%d%d",a[0],0);
        }
    }else{
        if(count2!=0 && count3!=0){
            printf("%d%d%d",a[0],a[1],a[2]);
        }else if(count2!=0 && count3 == 0){
            printf("%d%d%d",a[0],a[1],0);
        }else if(count2==0 && count3 != 0){
            printf("%d%d%d",a[0],0,a[2]);
        }else{
            printf("%d%d%d",a[0],0,0);
        }
    }
    
    return 0;
}