#include <bits/stdc++.h>
using namespace std;
int main(int argc, char *argv[]) {
  int N, M;
  int s[10], c[10];
  int a[105] = {0};
  cin >> N >> M;
  for (int i = 0; i < M; i++) {
    cin >> s[i] >> c[i];
  }
  for (int i = 0; i < M; i++) {
    if (s[i] == 1 && c[i] == 0) {
      if (N == 2 || N == 3) {
        cout << -1 << endl;
        return 0;
      }
    }
  }
  if (M == 0) {
    if (N == 1) {
      cout << 0 << endl;
    } else if (N == 2) {
      cout << 10 << endl;
    } else {
      cout << 100 << endl;
    }
    return 0;
  }
  int tmp[3] = {-1, -1, -1};
  for (int i = 0; i < M; i++) {
    if (tmp[s[i] - 1] == -1 || tmp[s[i] - 1] == c[i]) {
      tmp[s[i] - 1] = c[i];
    } else {
      cout << -1 << endl;
      return 0;
    }
  }
  for (int i = 0; i < N; i++) {
    if (tmp[i] == -1) {
      printf("0");
    } else {
      printf("%d", tmp[i]);
    }
  }
  puts("");
  return 0;
}
