#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 (s < N && c != 0) {
      cout << -1 << endl;
      return (0);
    }
    if (Z[s - 1] == -1)
      Z[s - 1] = c;
    else if (Z[s - 1] == c)
      ;
    else {
      cout << -1 << endl;
      return (0);
    }
  }
  if (N == 3 && Z[0] == 0) {
    cout << -1 << endl;
    return (0);
  }
  if (N == 2 && Z[1] == 0) {
    cout << -1 << endl;
    return (0);
  }
  if (N == 2 && Z[0] != -1) {
    cout << -1 << endl;
    return (0);
  }
  if (N == 1 && Z[0] != -1) {
    cout << -1 << endl;
    return (0);
  }
  if (N == 1 && Z[1] != -1) {
    cout << -1 << endl;
    return (0);
  }
  if (N == 3) {
    if (Z[0] == -1) Z[0] = 1;
    if (Z[1] == -1) Z[1] = 0;
    if (Z[2] == -1) Z[2] == 0;
  }
  if (N == 2) {
    if (Z[1] == -1) Z[1] = 1;
    if (Z[2] == -1) Z[2] = 0;
  }
  int ans = 0;
  for (int i = N - 1; i >= 0; i--) {
    if (Z[2 - i] == -1) Z[i] = 0;
    ans = ans * 10 + Z[2 - i];
  }
  cout << ans << endl;
}
