#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using st = string;
using db = double;
using vll = vector<long long>;
using vvll = vector<vll>;
using vst = vector<st>;
using vchar = vector<char>;
using pll = pair<ll, ll>;
using vpll = vector<pll>;
using vvpll = vector<vpll>;
ll mod = 1000000007;
int main() {
  ll n;
  cin >> n;
  vll num(n, -1);
  ll m;
  cin >> m;
  vll s(m), c(m);
  for (int i = (int)(0); i < (int)(m); i++) cin >> s.at(i) >> c.at(i);
  for (int i = (int)(0); i < (int)(m); i++) {
    if (num.at(s.at(i) - 1) == -1) {
      num.at(s.at(i) - 1) = c.at(i);
    } else {
      if (num.at(s.at(i) - 1) != c.at(i)) {
        cout << -1 << endl;
        return 0;
      }
    }
  }
  for (int i = (int)(0); i < (int)(n); i++) {
    if (num.at(i) == -1) {
      if (i == 0)
        num.at(i) = 1;
      else
        num.at(i) = 0;
    }
    if (i == 0 && num.at(i) == 0) {
      cout << -1 << endl;
      return 0;
    }
    cout << num.at(i);
  }
  cout << endl;
}
