#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#pragma GCC target("avx2")
#pragma GCC optimization("unroll-loops")
template <typename T>
ll gcd(T a, T b) {
  return b ? gcd(b, a % b) : a;
}
template <typename T>
ll lcm(T a, T b) {
  return a * b / gcd(a, b);
};
template <typename T>
inline void chmin(T& a, const T& b) {
  if (a > b) a = b;
}
template <typename T>
inline void chmax(T& a, const T& b) {
  if (a < b) a = b;
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n, m;
  cin >> n >> m;
  ll ans = 0;
  vector<int> main(n + 5, 0);
  bool flag = true;
  for (int i = 0; i < m; ++i) {
    int a, b;
    cin >> a >> b;
    if (main[a - 1] != 0) {
      if (main[a - 1] != b) {
        flag = false;
        break;
      }
    } else if (a == 1 && n > 1 && b == 0) {
      flag = false;
      break;
    } else {
      main[a - 1] = b;
    }
  }
  for (int i = 0; i < n; ++i) {
    ans += main[i] * pow(10, 2 - i);
  }
  if (flag) {
    cout << ans << '\n';
  } else {
    cout << -1 << '\n';
  }
}
