#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;
  long long N, M, K;
  long long ans = 0;
  int flag = 0;
  int A[3] = {0};
  A[0] = -1;
  A[1] = -1;
  A[2] = -1;
  cin >> N >> M;
  for ((i) = 0; i < (int)(M); i++) {
    int s, c;
    cin >> s >> c;
    s--;
    if (A[s] == -1 || A[s] == c)
      A[s] = c;
    else {
      flag = -1;
    }
  }
  if (A[0] == -1) A[0] = 1;
  if (A[0] == 0 || flag == -1) {
    cout << -1;
    return 0;
  }
  cout << A[0];
  for (i = 1; i < N; i++) {
    if (A[i] == -1) A[i] = 0;
    cout << A[i];
  }
  return 0;
}
