#include <bits/stdc++.h>
using namespace std;
using ll = long long int;
using bigint = int64_t;
const int MOD = 1000000007;
void io_set() {}
void solve() {
  ll n, m, x, y;
  cin >> n >> m;
  ll a[n + 1], flag = 0;
  for (ll i = 0; i < n + 1; i++) {
    a[i] = -1;
  }
  map<ll, ll> p;
  set<pair<ll, ll> > s;
  for (ll i = 0; i < m; i++) {
    cin >> x >> y;
    s.insert({x, y});
    if (x == 1 && y == 0) {
      flag = 1;
      break;
    }
    if (a[x] == y || a[x] == -1) {
      p[x] = 1;
      a[x] = y;
    } else {
      flag = 1;
    }
  }
  if (n == 1 && (int)s.size() == 1) {
    for (auto it : s) {
      if (it.first == 1 && it.second == 0) {
        cout << 0;
        return;
      }
    }
  }
  if (flag) {
    cout << -1;
  } else {
    if (a[1] == 0) {
      a[1] = 1;
    }
    for (ll i = 1; i <= n; i++) {
      if (a[i] == -1) {
        cout << 0;
      } else {
        cout << a[i];
      }
    }
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  cout.tie(nullptr);
  ;
  io_set();
  ll tt = 1;
  while (tt--) {
    solve();
  }
  return 0;
}
