#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using vl = vector<ll>;
template <class T>
using vc = vector<T>;
template <class T>
using vvc = vector<vector<T>>;
const ll MOD = 1e9 + 7;
const ll INF = 1e16;
const ld EPS = 1e-11;
const ld PI = acos(-1.0L);
template <class T>
bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T>
bool chmin(T &a, const T &b) {
  if (b < a) {
    a = b;
    return 1;
  }
  return 0;
}
void init() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(15);
}
int main() {
  init();
  ll N, M;
  cin >> N >> M;
  vl A(N, -1);
  for (ll i = 0; i < (M); i++) {
    ll s, c;
    cin >> s >> c;
    s--;
    if (A[s] != -1 && A[s] != c) {
      cout << -1 << endl;
      return 0;
    }
    A[s] = c;
  }
  string ans = "";
  for (ll i = 0; i < (N); i++) {
    if (i == 0 && A[0] == -1)
      ans += '1';
    else if (A[i] == -1)
      ans += '0';
    else {
      ans += '0' + A[i];
    }
  }
  if (A[0] == 0 && N > 1) {
    cout << -1 << endl;
    return 0;
  } else if (A[0] == 0) {
    cout << 0 << endl;
    return 0;
  }
  cout << ans << endl;
}
