#include <stdio.h>
#include <math.h>

#define DEBUG (0)

int main(void)
{
  int N = 0;
  int M = 0;
  int judge = 0;	/* 0:OK, 1:NG */
  int dispNum = 0;	/* 結果表示用10進数 */
  
  scanf("%d %d",&N, &M);
  
  /* Guess Number:N桁数字（配列） -1 で初期化 */
  int g_num[N];
  for(int i = 0; i < N; i++){
    g_num[i] = -1;
#if DEBUG
    printf("g_num[%d] = %d\n",i, g_num[i]);
#endif
  }
  

  /* 入力データ M行2列 */
  int input[M][2] = {0};
  for(int i = 0; i < M; i++){
    scanf("%d %d", &input[i][0], &input[i][1]);
  }
#if DEBUG
  for(int i = 0; i < M; i++){
    printf("input : %d %d\n",input[i][0], input[i][1]);
  }
#endif
  
  /* M個のデータ分 g_numチェック */
  for(int i = 0; i < M; i++){
    if(g_num[input[i][0]-1] == -1){
      /* g_numの上からi桁目に値代入 */
      g_num[input[i][0]-1] = input[i][1];
#if DEBUG
      printf("AAAAA\n");
      for(int j = 0; j < N; j++){
	    printf("g_num1[%d] = %d\n",j, g_num[j]);
	  }

#endif
    }else if(g_num[input[i][0]-1] == input[i][1]){
      /* do nothing*/
#if DEBUG
      printf("BBBBB\n");
#endif
    }else{
#if DEBUG
      printf("CCCCC\n");
      printf("i = %d, g_num = :%d\n",i, g_num[i]);
#endif
      judge = -1;
      break;
    }
  }

  if(judge == -1){
    printf("-1");
  }else{
    /* 最小の値を算出して表示 */
    for(int i = 0; i < N; i++){
      if(g_num[i] == -1){
        g_num[i] = 0;
      }
    }
    for(int i = 0; i < M; i++){
	    dispNum = dispNum + g_num[i] * (int)pow(10,M - i - 1) ;
    }
    if(dispNum >= (int)pow(10,M-1)){
      printf("%d", dispNum);
    }else{
      printf("-1");
    }
  }
  
}