z#include <bits/stdc++.h>
using namespace std;
#define rep(i, seisu) for(int i = 0; i < (int)(seisu); i++)
typedef long long ll;



int main() {
  int n, m; ///n桁の数
  cin >> n >> m;
  int f = 0;
  vector<int> num(n, 0);
  rep(i, m){
    int s, c; ///s桁目の数がc
    cin >> s >> c;


    if(c == 0 && s == 1 && n!= 1) {
      f = 1;
      break;
    }
    else if(num[s-1] != 0 && num[s-1] != c){
      f = 1;
      break;
    }
    else num[s-1] = c;
  }
  if (f == 1) cout << "-1" << endl;
  else{
    rep(i, n){
      if (num[i] != 0) f = 2;
    }
    if (f == 2){
      rep(i, n) cout << num[i];
    }
    else cout << 0;
  
  }

  }
