#include <bits/stdc++.h>
using namespace std;
long gcd(long long a, long long b) {
  if (a % b == 0) {
    return b;
  } else {
    return gcd(b, a % b);
  }
}
long lcm(long long a, long long b) { return a / gcd(a, b) * b; }
template <typename A, typename B>
inline bool chmax(A &a, B b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <typename A, typename B>
inline bool chmin(A &a, B b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
const long long INF = 1ll << 60;
const long long MOD = 1000000007;
const double EPS = 1e-10;
int n, m;
pair<int, int> c[5];
int num[3];
int f;
int main() {
  cin >> n >> m;
  for (long long i = (0); i < (m); i++) {
    cin >> c[i].first >> c[i].second;
    if (num[c[i].first - 1] == c[i].second || num[c[i].first - 1] == 0)
      num[c[i].first - 1] = c[i].second;
    else
      f = -1;
  }
  if (num[0] == 0) {
    if (n == 1)
      f = 1;
    else
      f = -1;
  }
  if (f == 1)
    cout << 0 << endl;
  else if (f == -1)
    cout << -1 << endl;
  else {
    for (long long i = (0); i < (3); i++) cout << num[i];
    cout << endl;
  }
  return 0;
}
