#include <bits/stdc++.h>
using namespace std;
int times10(int n) {
  int output = 1;
  for (int i = 0; i < n; i++) {
    output *= 10;
  }
  return output;
}
int main() {
  int N, M;
  cin >> N >> M;
  vector<int> s(M);
  vector<int> c(M);
  for (int i = 0; i < M; i++) {
    cin >> s[i] >> c[i];
    s[i]--;
  }
  vector<int> output(N, -1);
  if (M == 0) {
    if (N == 1) {
      cout << 0 << endl;
      return 0;
    } else {
      cout << -1 << endl;
      return 0;
    }
  }
  for (int i = 0; i < M; i++) {
    if (N > 0 && s[i] == 0 && c[i] == 0) {
      cout << -1 << endl;
      return 0;
    }
    if (output[s[i]] == -1) {
      output[s[i]] = c[i];
    } else if (output[s[i]] == c[i]) {
      continue;
    } else {
      cout << -1 << endl;
      return 0;
    }
  }
  int num;
  if (output[0] == -1) {
    if (N == 0) {
      num = 0;
    } else {
      num = times10(N - 1);
    }
  } else {
    num = times10(N - 1) * output[0];
  }
  for (int i = 1; i < N; i++) {
    if (output[i] != -1) {
      num += times10(N - 1 - i) * output[i];
    }
  }
  cout << num << endl;
  return 0;
}
