#include <bits/stdc++.h>
using namespace std;
int main(void) {
  int N, M;
  cin >> N >> M;
  int C[5];
  int S[5];
  bool flag = false;
  for (int i = 0; i < M; i++) {
    cin >> C[i] >> S[i];
    if (N != 1 && C[i] == 1 && S[i] == 0) {
      flag = true;
    }
  }
  if (flag) {
    cout << -1;
    return 0;
  }
  bool check[] = {false, false, false};
  int ans[] = {0, 0, 0};
  for (int i = 0; i < M; i++) {
    int d = 3 - N - 1 + C[i];
    if (check[d] == false) {
      check[d] = true;
      ans[d] = S[i];
    } else {
      if (ans[d] != S[i]) {
        cout << -1;
        return 0;
      }
    }
  }
  for (int i = 0; i < N; i++) {
    int d = 3 - N + i;
    if (check[d] == false) {
      if (i == 0) {
        ans[d] = 1;
      } else {
        ans[d] = 0;
      }
    }
  }
  cout << 100 * ans[0] + 10 * ans[1] + ans[2];
  return 0;
}
