#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
using vi = vector<int>;
using vl = vector<ll>;
using vs = vector<string>;
using vb = vector<bool>;
using vp = vector<P>;
const int INF = 1e9;
const int MOD = 1e9 + 7;
vi f(10), inv(10);
void trans(string &n) {
  for (int i = 0; i < (n.length()); i++) {
    n[i] = f[n[i] - '0'] + '0';
  }
}
void invtrnas(string &n) {
  for (int i = 0; i < (n.length()); i++) {
    n[i] = inv[n[i] - '0'] + '0';
  }
}
signed main() {
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(15);
  int N, M;
  cin >> N >> M;
  vi num(N, -1);
  vi s(M), c(M);
  for (int i = 0; i < (M); i++) cin >> s[i] >> c[i];
  for (int i = 0; i < (M); i++) {
    if (s[i] == 1 && c[i] == 0) {
      cout << -1 << endl;
      return 0;
    }
    if (num[s[i] - 1] != -1 && num[s[i] - 1] != c[i]) {
      cout << -1 << endl;
      return 0;
    }
    num[s[i] - 1] = c[i];
  }
  for (int i = N - 1; i >= 0; i--) {
    if (num[i] == -1) num[i] = 0;
  }
  if (num[N - 1] == 0) num[N - 1] = 1;
  int ans = 0;
  for (int i = 0; i < (N); i++) {
    ans *= 10;
    ans += num[i];
  }
  cout << ans << endl;
}
