#include <iostream>
#include <cstring>
#include <algorithm>
#include <functional>
#include <bits/stdc++.h>
#include <cmath>
using namespace std;
 
int main () {
  int n, m;
  cin >> n >> m;
  int s[n] = {0};
  //if (n != 1) s[0] = 1;
  bool f = true;
  for (int i = 0; i < m; i++){
    int ts, tc;
    cin >> ts >> tc;
    if (n>1 && ts==1 && tc ==0){
      f = false;
      break;
    }
    if (s[ts-1]==tc || s[ts-1]==0){
      s[ts-1]=tc;
    }else{
      f = false;
      break;
    }
  }
  if (f){
    for (int j=0; j<n; j++){
      cout << s[j];
    }
  }else{
    cout <<"-1";
  }
  return 0;
}