#include <bits/stdc++.h>
using namespace std;
long long n, m;
int main() {
  cin >> n >> m;
  long long x[n];
  for (long long i0 = 0; i0 < n; i0++) {
    x[i0] = 10;
  }
  long long ans = 0;
  for (long long i1 = 0; i1 < m; i1++) {
    long long s;
    long long c;
    cin >> s >> c;
    if (x[s - 1] == 10) {
      x[s - 1] = c;
    } else if (x[s - 1] != c) {
      ans = -1;
    }
  }
  if (n > 1 && x[0] == 0) ans = -1;
  if (ans != -1) {
    for (long long i2 = 0; i2 < n; i2++) {
      if (x[i2] == 10) x[i2] = 0;
      ans += (x[i2] * pow(10, n - 1 - i2));
    }
  }
  cout << ans << endl;
  return 0;
}
