#include <bits/stdc++.h>
using namespace std;
int main() {
  int N, M;
  cin >> N >> M;
  int flag = 0;
  if (N == 1 && M == 1) flag = 1;
  vector<int> tmp(N);
  tmp = {10, 10, 10};
  vector<int> check(N);
  for (int i = 0; i < N; i++) {
    check[i] = 0;
  }
  int ans = 0;
  for (int i = 0; i < M; i++) {
    int s, c;
    cin >> s >> c;
    if (s == 0 && c == 0 && flag == 1) {
      ans = 0;
      flag = 2;
      break;
    }
    if (check[s - 1] == 1) {
      if (tmp[s - 1] != c) {
        ans = -1;
        break;
      }
    } else
      check[s - 1] = 1;
    tmp[s - 1] = c;
    if (N != 1 && tmp[0] == 0) {
      ans = -1;
      break;
    }
  }
  if (ans != -1 && flag != 2) {
    for (int i = 0; i < N; i++) {
      int a;
      a = tmp[i];
      if (i == 0 && a == 10) {
        tmp[i] = 1;
      }
      if (i != 0 && a == 10) {
        tmp[i] = 0;
      }
    }
    int kake = 100;
    if (N == 2) kake = 10;
    if (N == 1) kake = 1;
    for (int i = 0; i < N; i++) {
      ans += tmp[i] * kake;
      kake /= 10;
    }
  }
  cout << ans << endl;
}
