#include <bits/stdc++.h>
using namespace std;
int main(void) {
  int s[5], c[5], N, M, i;
  int num = 0, ret = 0, temp;
  int flg[3] = {0};
  cin >> N >> M;
  for (i = 0; i < M; i++) {
    cin >> s[i] >> c[i];
    if (s[i] == 1 && c[i] == 0) {
      num = -1;
      break;
    }
    if (flg[s[i] - 1] == 0) {
      flg[s[i] - 1] = 1;
      num += pow(10, N - s[i]) * c[i];
    } else {
      temp = (int)pow(10, N - s[i] + 1);
      if ((int)(num / pow(10, N - s[i])) % temp == c[i]) {
      } else {
        num = -1;
        break;
      }
    }
  }
  if (num == -1) {
    cout << num;
  } else {
    for (i = 0; i < N; i++) {
      if (flg[i] == 0) {
        if (i == 0) {
          num += pow(10, N - 1);
        }
      }
    }
    cout << num;
  }
}
