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

int main(){
  int n, m;
  cin >> n >> m;
  int ans = pow(10,n-1);
  if n==1 ans = 0;
  vector<int> check(3);
  rep(i,m){
    int s, c;
    cin >> s >> c;
    if (n>1 && s == 1 && c == 0){
      ans = -1;
      break;
    }
    if (check[s-1]!=0){
      if (check[s-1]==c) continue;
      else {
      ans =-1;
      break;
    }
    }
    
    ans += pow(10,(n-s))*c;
    check[s-1]=c;
  }
  cout << ans;
}
    