#include <bits/stdc++.h>
template <class T>
bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T>
bool chmin(T &a, const T &b) {
  if (b < a) {
    a = b;
    return 1;
  }
  return 0;
}
using ll = long long;
using namespace std;
ll GetNum(ll N, ll M, const vector<ll> &s, const vector<ll> &c) {
  int num[3]{-1, -1, -1};
  for (int i = 0, i_len = (M); i < i_len; ++i) {
    ll index = s[i] - 1;
    if ((num[index] == -1) || (num[index] == c[i])) {
      num[index] = c[i];
    } else {
      return -1;
    }
  }
  if ((num[0] == -1) && (1 < N)) {
    return -1;
  }
  if ((num[0] == 0) && (1 < N)) {
    return -1;
  }
  for (int i = 0, i_len = (3); i < i_len; ++i) {
    if (num[i] == -1) {
      num[i] = 0;
    }
  }
  switch (N) {
    case 1:
      return num[0];
    case 2:
      return num[0] * 10 + num[1];
    case 3:
      return num[0] * 100 + num[1] * 10 + num[2];
  }
  return -1;
}
int main() {
  ll N, M;
  cin >> N >> M;
  vector<ll> s, c;
  for (int i = 0, i_len = (M); i < i_len; ++i) {
    ll tmp;
    cin >> tmp;
    s.emplace_back(tmp);
    cin >> tmp;
    c.emplace_back(tmp);
  }
  ll result = GetNum(N, M, s, c);
  cout << result << endl;
  return 0;
}
