#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vl = vector<ll>;
using vc = vector<char>;
using vvl = vector<vl>;
using vvc = vector<vc>;
using pll = pair<ll, ll>;
using vpll = vector<pll>;
int main() {
  ll N, M;
  cin >> N >> M;
  vl s(M), c(M);
  for (int i = 0; i < (int)(M); i++) cin >> s[i] >> c[i];
  map<ll, ll> num;
  for (int i = (int)(1); i < (int)(10); i++) num[i] = -1;
  for (int i = 0; i < (int)(M); i++) {
    if ((num[s[i]] > -1) && (num[s[i]] != c[i])) {
      cout << -1 << "\n";
      return 0;
    }
    if ((s[i] == 1) && (c[i] == 0)) {
      cout << -1 << "\n";
      return 0;
    }
    num[s[i]] = c[i];
  }
  for (int i = (int)(1); i < (int)(N + 1); i++) {
    if (num[i] > -1) {
      cout << num[i];
    } else {
      if (i == 1)
        cout << 1;
      else
        cout << 0;
    }
  }
  cout << "\n";
  return 0;
}
