#include <bits/stdc++.h>
using namespace std;
int check(int x) {
  if (x == 0) return 1;
  int num = 0;
  while (x) {
    num++;
    x /= 10;
  }
  return num;
}
void solve(long long N, long long M, std::vector<long long> s,
           std::vector<long long> c) {
  vector<int> a(N);
  for (unsigned int i = 0; i < N; i++) a[i] = -1;
  for (int i = 0; i < M; i++) {
    if (a[s[i] - 1] == -1)
      a[s[i] - 1] = c[i];
    else if (a[s[i] - 1] != c[i]) {
      cout << -1 << endl;
      return;
    }
  }
  int fn0 = 0;
  while (a[fn0] != -1) fn0++;
  for (int i = 0; i < M; i++) {
    if (s[i] - 1 < fn0 && c[i] == 0) {
      cout << -1 << endl;
      return;
    }
  }
  int num = 0;
  bool flag = true;
  for (int i = 0; i < N; i++) {
    if (a[i] == -1) {
      if (i < fn0 && flag)
        a[i] = 1, flag = false;
      else
        a[i] = 0;
    }
    num = num * 10 + a[i];
  }
  int checknum = check(num);
  if (checknum == N)
    cout << num << endl;
  else if (checknum) {
    for (int i = 1; i < fn0; i++) cout << 1;
    cout << num << endl;
  } else
    cout << -1 << endl;
}
int main() {
  long long N;
  scanf("%lld", &N);
  long long M;
  scanf("%lld", &M);
  std::vector<long long> s(M);
  std::vector<long long> c(M);
  for (int i = 0; i < M; i++) {
    scanf("%lld", &s[i]);
    scanf("%lld", &c[i]);
  }
  solve(N, M, std::move(s), std::move(c));
  return 0;
}
