#include <bits/stdc++.h>
using namespace std;
const int INF = INT_MAX;
const int MAX = 510000;
const long long MOD = 1000000007;
long long fac[MAX], finv[MAX], inv[MAX];
int main() {
  long long n, m;
  cin >> n >> m;
  vector<long long> c(n, -1);
  bool ok = false;
  for (long long i = (0); i < (m); ++i) {
    long long s, a;
    cin >> s >> a;
    if (c[s - 1] != -1 && c[s - 1] != a) {
      ok = true;
      break;
    } else {
      c[s - 1] = a;
    }
  }
  if (n != -1 && c[0] == 0) ok = true;
  if (ok) {
    cout << -1 << endl;
  } else {
    long long ans = 0;
    for (long long i = (0); i < (n); ++i) {
      if (c[i] != -1) ans += c[i] * pow(10, n - 1 - i);
    }
    cout << ans << endl;
  }
}
