#include <bits/stdc++.h>
using ll = long long;
using graph = std::vector<std::vector<ll>>;
using namespace std;
int main() {
  ll N, M;
  cin >> N >> M;
  pair<ll, ll> req[M];
  ll val[N];
  for (int i = 0; i < N; ++i) {
    val[i] = -1;
  }
  for (int i = 0; i < M; ++i) {
    ll s, c;
    cin >> s >> c;
    req[i] = make_pair(s, c);
  }
  for (int i = 0; i < M; ++i) {
    if (req[i].first == 1 && req[i].second == 0) {
      if (N == 1) {
        cout << 0 << endl;
      } else {
        cout << -1 << endl;
      }
      return 0;
    }
    if (val[req[i].first - 1] != -1) {
      if (val[req[i].first - 1] != req[i].second) {
        cout << -1 << endl;
        return 0;
      }
    }
    val[req[i].first - 1] = req[i].second;
  }
  for (int i = 0; i < N; ++i) {
    if (val[i] == -1) {
      if (i == 0) {
        cout << 1;
      } else {
        cout << 0;
      }
    } else {
      cout << val[i];
    }
  }
  cout << endl;
}
