#include <bits/stdc++.h>
int main(int argc, char *argv[]) {
  int n, m;
  int num[3] = {-1, -1, -1};
  bool exist = true;
  std::cin >> n >> m;
  for (int i = 0; i < m; i++) {
    int s, c;
    std::cin >> s >> c;
    if (s > n) {
      exist = false;
      continue;
    }
    if ((num[s - 1] != -1) && (num[s - 1] != c)) {
      exist = false;
      continue;
    }
    if ((n > 1) && (s == 1) && (c == 0)) {
      exist = false;
      continue;
    }
    num[s - 1] = c;
  }
  if (num[0] == -1) {
    num[0] = 1;
  }
  for (int i = 0; i < 3; i++) {
    if (num[i] == -1) {
      num[i] = 0;
    }
  }
  if (exist) {
    const int mul[6] = {0, 0, 0, 1, 10, 100};
    const int ans = num[2] * mul[n] + num[1] * mul[n + 1] + num[0] * mul[n + 2];
    std::cout << ans << std::endl;
  } else {
    std::cout << -1 << std::endl;
  }
  return 0;
}
