#include <bits/stdc++.h>
using namespace std;
long long gcd(long long a, long long b) {
  if (b == 0) return a;
  return gcd(b, a % b);
}
long long lcm(long long a, long long b) { return a / gcd(a, b) * b; }
int main() {
  int i, j, k;
  int N, M, K;
  cin >> N >> M;
  int A[3] = {-1, -1, -1};
  for ((i) = 0; i < (int)(M); i++) {
    int a, b;
    cin >> a >> b;
    a--;
    if (A[a] != -1 && A[a] != b) {
      cout << -1;
      return 0;
    }
    A[a] = b;
  }
  if (A[0] == 0 && N != 1) {
    cout << -1;
    return 0;
  }
  if (A[0] == -1) A[0] = 1;
  cout << A[0];
  for ((i) = 1; i < (int)(N); i++) {
    if (A[i] == -1) {
      A[i] = 0;
    }
    cout << A[i];
  }
  return 0;
}
