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