#include <bits/stdc++.h>
using namespace std;
int main() {
  int M, N;
  cin >> N >> M;
  vector<int> s(M), c(M);
  for (int i = 0; i < M; i++) {
    cin >> s[i] >> c[i];
  }
  vector<int> a(N);
  vector<int> f(N);
  for (int i = 0; i < M; i++) {
    if (f[s[i] - 1] == 0) {
      if ((s[i] == 1) && (c[i] == 0)) {
        cout << -1 << endl;
        return 0;
      }
      f[s[i] - 1] = 1;
      a[s[i] - 1] = c[i];
    } else {
      if (a[s[i] - 1] != c[i]) {
        cout << -1 << endl;
        return 0;
      }
    }
  }
  int r = 0;
  if (a[0] == 0) {
    if (N == 1) {
      cout << r << endl;
      return 0;
    }
    r += pow(10, N - 1);
  } else {
    r += a[0] * pow(10, N - 1);
  }
  for (int i = 0; i < N - 1; i++) {
    r += a[i + 1] * pow(10, N - i - 2);
  }
  cout << r << endl;
  return 0;
}
