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

int main()
{
  int n,m;
  cin >> n >> m;
  int s[m];
  int c[m];
  int ans = 0;
  bool f=0;
  rep(i, m){
    cin >> s[i] >> c[i];
    rep(j, i){
      if(!(s[i] == s[j])){
        ans += c[i] * pow(10, n-s[i]);
      } else if(!(c[i] == c[j])){
        f = 1;
      }
    }
    if(c[i] == 0 && s[i] == 1) f = 1;
  }
  if(ans < pow(10, n-1)) ans += pow(10, n-1)
  if(f) ans = -1;
  cout << ans << endl;
  
  return 0;
}
