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