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