#include <bits/stdc++.h>
using namespace std;
int main() {
  int nums[3];
  for (int i = 0; i < 3; i++) nums[i] = -1;
  int n, m;
  int t1;
  int t2;
  cin >> n >> m;
  for (int i = 0; i < m; i++) {
    cin >> t1 >> t2;
    if (nums[t1 - 1] != -1 && nums[t1 - 1] != t2) {
      printf("-1\n");
      return 0;
    } else {
      nums[t1 - 1] = t2;
    }
  }
  if (nums[0] == 0) {
    printf("-1\n");
    return 0;
  }
  int num = 0;
  for (int i = 0; i < n; i++) {
    num *= 10;
    if (nums[i] == -1) {
      if (i == 0) {
        num += 1;
      } else {
        num += 0;
      }
    } else {
      num += nums[i];
    }
  }
  printf("%d\n", num);
}
