#include <bits/stdc++.h>
using namespace std;
void func(long long N, long long M, std::vector<long long> s,
          std::vector<long long> c) {
  int num[3];
  for (int i = 0, i_len = (3); i < i_len; i++) num[i] = -1;
  for (int i = 0, i_len = (M); i < i_len; i++) s[i]--;
  for (int i = 0, i_len = (M); i < i_len; i++) {
    int si = s[i];
    int ci = c[i];
    if (num[si] != -1) {
      if (num[si] != ci) {
        cout << -1 << endl;
        return;
      }
    }
    num[si] = ci;
  }
  for (int i = 0, i_len = (3); i < i_len; i++) {
    if (num[i] == -1) {
      if (i == 0) num[i] = 1;
      if (i != 0) num[i] = 0;
    }
  }
  if (num[0] == 0) {
    cout << -1 << endl;
    return;
  }
  int ans = 0;
  for (int i = 0, i_len = (N); i < i_len; i++)
    ans += num[i] * pow(10, N - 1 - i);
  cout << ans << 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]);
  }
  func(N, M, std::move(s), std::move(c));
  return 0;
}
