#include <bits/stdc++.h>
using namespace std;
int main() {
  int N, M;
  cin >> N >> M;
  vector<int> s(M), c(M);
  for (int j = 0; j < M; j++) {
    cin >> s[j] >> c[j];
    s[j]--;
  }
  int t = 1;
  int x[N];
  x[0] = -1;
  for (int i = 1; i < N; i++) {
    t *= 10;
    x[i] = -1;
  }
  bool ok = true;
  for (int i = t; i < t * 10; i++) {
    for (int j = 0; j < M; j++) {
      if (x[s[j]] == c[j] || x[s[j]] == -1) {
        x[s[j]] = c[j];
      } else {
        ok = false;
      }
      if (x[0] == 0 && N > 0) ok = false;
    }
  }
  if (ok) {
    if (x[0] == -1) {
      if (N == 1)
        cout << 0;
      else
        cout << 1;
    } else
      cout << x[0];
    for (int i = 1; i < N; i++) {
      if (x[i] == -1)
        cout << 0;
      else
        cout << x[i];
    }
    cout << endl;
  } else
    cout << -1 << endl;
  return 0;
}
