#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  map<int, int> A;
  for (int i = 1; i <= 3; i++) {
    A.insert({i, -1});
  }
  for (int i = 0; i < m; i++) {
    int a, b;
    cin >> a >> b;
    if (a > n) {
      cout << "-1"
           << "\n";
      return 0;
    }
    if (A[a] != -1 && A[a] != b) {
      cout << "-1"
           << "\n";
      return 0;
    }
    A[a] = b;
  }
  int l = 0;
  int y = -1;
  for (int i = n - 1; i > 0; i--) {
    y = max(y, A[i]);
  }
  if (y == 0 && A[n] == -1) {
    cout << "-1"
         << "\n";
    return 0;
  }
  for (int i = 1; i <= n; i++) {
    if (A[i] == -1 && i != 1)
      A[i] = 0;
    else if (A[i] == -1)
      A[i] = 1;
    l += A[i] * pow(10, n - i);
  }
  cout << l << "\n";
}
