#include <bits/stdc++.h>
using namespace std;
int main() {
  int N, M;
  cin >> N >> M;
  int ans = 1;
  if (M == 0) {
    for (int i = 0; i < N; i++) {
      ans *= 10;
    }
    cout << ans / 10 << endl;
    return 0;
  }
  vector<pair<int, int>> A(M);
  for (int i = 0; i < M; i++) {
    cin >> A[i].first >> A[i].second;
    if (A[i].first > N) {
      cout << -1 << endl;
      return 0;
    }
    if (A[i].first == 1) {
      A[i].second--;
    }
    if (A[i].second == -1) {
      cout << -1 << endl;
      return 0;
    }
  }
  vector<int> ten = {100, 10, 1};
  ans = ten[3 - N];
  vector<int> seki(3, -1);
  for (int i = 0; i < M; i++) {
    if (seki[A[i].first - 1] != -1 && seki[A[i].first - 1] != A[i].second) {
      cout << -1 << endl;
      return 0;
    } else
      seki[A[i].first - 1] = A[i].second;
  }
  for (int i = 0; i < 3; i++) {
    if (seki[i] == -1) {
      seki[i] = 0;
    }
    ans += seki[i] * ten[i];
  }
  cout << ans << endl;
  return 0;
}
