#include <bits/stdc++.h>
using namespace std;
namespace Arithmetics {
template <typename T>
T original_pow(T a, T b) {
  T ans = 1;
  for (int i = 0; i < (int)(b); i++) {
    ans *= a;
  }
  return ans;
}
template <typename T>
T gcd(T a, T b) {
  if (a > b) {
    T c = a;
    a = b;
    b = c;
  }
  if (a == 0) {
    return b;
  }
  return gcd(b % a, a);
}
template <typename T>
T gcd_of_all(vector<T> v) {
  T temp = v[0];
  for (T elem : v) {
    temp = gcd(temp, elem);
  }
  return temp;
}
template <typename T>
T lcm(T a, T b) {
  T GCD = gcd(a, b);
  return a * b / GCD;
}
template <typename T>
T lcm_of_all(vector<T> v) {
  T temp = v[0];
  for (T elem : v) {
    temp = lcm(temp, elem);
  }
  return temp;
}
}  // namespace Arithmetics
using namespace Arithmetics;
void prob157() {
  int N, M;
  cin >> N >> M;
  vector<int> vec(3, -1);
  bool flag = true;
  for (int i = 0; i < (int)(M); i++) {
    int s, c;
    cin >> s >> c;
    s--;
    if (s == 0 and c == 0) flag = false;
    if (vec[s] != -1) {
      if (vec[s] != c) flag = false;
    }
    vec[s] = c;
  }
  for (int i = 0; i < (int)(3); i++) {
    if (vec[i] == -1) {
      vec[i] = 0;
    }
  }
  if (flag) {
    cout << 100 * vec[0] + 10 * vec[1] + vec[2] << endl;
  } else {
    cout << -1 << endl;
  }
}
int main() { prob157(); }
