#include <bits/stdc++.h>
using namespace std;
using LL = long long;
template <class T>
ostream &operator<<(ostream &os, const vector<T> &t) {
  os << "[";
  for (__typeof((t).begin()) it = (t).begin(); it != (t).end(); it++) {
    if (it != t.begin()) os << ",";
    os << *it;
  }
  os << "]";
  return os;
}
template <class T>
ostream &operator<<(ostream &os, const set<T> &t) {
  os << "{";
  for (__typeof((t).begin()) it = (t).begin(); it != (t).end(); it++) {
    if (it != t.begin()) os << ",";
    os << *it;
  }
  os << "}";
  return os;
}
template <class S, class T>
ostream &operator<<(ostream &os, const pair<S, T> &t) {
  return os << "(" << t.first << "," << t.second << ")";
}
void solve(long long N, long long M, std::vector<long long> s,
           std::vector<long long> c) {
  vector<LL> D(3, -1);
  for (int i = 0; i < (int)(M); i++) {
    int keta = s[i] - 1;
    int num = c[i];
    if (D[keta] == -1) {
      D[keta] = num;
    } else if (D[keta] != num) {
      cout << -1 << endl;
      return;
    }
  }
  int ans = 0;
  for (int i = 0; i < (int)(3); i++) {
    if (D[i] == -1) {
      D[i] = 0;
    }
    ans += D[i] * pow(10, 2 - 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]);
    if (s[i] == 1 && c[i] == 0) {
      cout << -1 << endl;
      return 0;
    }
  }
  solve(N, M, std::move(s), std::move(c));
  return 0;
}
