#include <bits/stdc++.h>
using namespace std;
int main() {
  int N, M;
  cin >> N >> M;
  int Z[3] = {-1, -1, -1};
  for (int i = 0; i < M; i++) {
    int s, c;
    cin >> s >> c;
    if (Z[s - 1] != -1 && Z[s - 1] != c) {
      cout << -1 << endl;
      return (0);
    }
    Z[s - 1] = c;
  }
  if (N == 1) {
    if ((Z[0] != -1 && Z[0] != 0) || (Z[1] != -1 && Z[1] != 0)) {
      cout << -1 << endl;
      return (0);
    }
  } else if (N == 2) {
    if ((Z[0] != -1 && Z[0] != 0) || Z[1] == 0) {
      cout << -1 << endl;
      return (0);
    }
  } else if (N == 3) {
    if (Z[0] == 0) {
      cout << -1 << endl;
      return (0);
    }
  }
  if (N == 1) {
    Z[0] = 0;
    Z[1] = 0;
    if (Z[2] == -1) Z[2] = 0;
  } else if (N == 2) {
    Z[0] = 0;
    if (Z[1] == -1) Z[1] = 1;
    if (Z[2] == -1) Z[2] = 0;
  } else if (N == 3) {
    if (Z[0] == -1) Z[0] = 1;
    if (Z[1] == -1) Z[1] = 0;
    if (Z[2] == -1) Z[2] = 0;
  }
  int ans = 0;
  for (int i = N - 1; i >= 0; i--) {
    ans = ans * 10 + Z[2 - i];
  }
  cout << ans << endl;
}
