#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
using namespace std;
using P = pair<int, int>; 
using ll = long long;
using M = map<int, int>;

int main()
{
  int n, m;
  cin >> n >> m;
  vector<int> v(n);
  rep(i, n) v[i] = -1;
  int a, b, ok = 0;
  int ans = 0;
  rep(i, m){
    cin >> a >> b;
    if(n == 1){
      v[0] = b;
    }
    else{
      if(v[a - 1] == -1) v[a - 1] = b;
      if(v[a - 1 != b) ans = -1;
    }        
  }
  rep(i, n){
    if(v[i] == -1) v[i] = 0;
  }
  if(ans > -1){
    if(n == 1) {
      cout << v[0] << endl;
      return 0;
    }
    if(n > 1 && v[0] == 0){
      cout << -1 << endl;
      return 0;
    }
    rep(i, n){
      ans *= 10;
      ans += v[i];
    }
  }
  cout << ans << endl;
        

  return 0;
}