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

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