#include <bits/stdc++.h>
using namespace std;
int main() {
  int N, M, n[3] = {-1, -1, -1}, num;
  bool b = true;
  cin >> N >> M;
  int s[M], c[M];
  for (int i = 0; i < M; i++) {
    cin >> s[i] >> c[i];
    s[i]--;
    if (n[s[i]] != -1) {
      if (n[s[i]] != c[i]) {
        b = false;
        break;
      }
    }
    n[s[i]] = c[i];
  }
  do {
    if (n[0] == 0) {
      if (N != 1) {
        b = false;
        break;
      }
    }
    if (n[1] == 0) {
      if (n[0] < 0) n[0] = 0;
    }
    if (n[2] == 0) {
      if (n[1] < 0) n[1] = 0;
    }
    for (int i = 0; i < 3; i++) {
      if (n[i] < 0) n[i] = 0;
    }
  } while (false);
  num = pow(10, N - 1) * n[0] + pow(10, N - 1) * n[1] / 10 + n[2];
  cout << (b ? num : -1);
}
