#include <iostream>
#include <stdio.h>

#define rep(i,min,sup) for(int i=min;i<sup;i++)
#define per(i,min,sup) for(int i=(sup-1);i>=min;i--)
#define swap(a,b) {a+=b;b=a-b;a-=b;}
#define ll long long

using namespace std;

main(){
  int N,M;
  scanf("%d %d",&N,&M);
  int ans[N]={};
  rep(i,0,M){
    int s,c;
    scanf("%d %d",&s,&c);
    s--;c++;
    if(ans[s]&&ans[s]!=c){printf("-1");return 0;}
    ans[s]=c;
  }
  if(N>1&&!ans[0])ans[0]=2;
  rep(i,0,N)if(ans[i])ans[i]--;
  rep(i,0,N)printf("%d",ans[i]);
}