#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;
  bool flag = true;
  map<int, int> mp;
  for (int i = 0; i < m; ++i) {
    int a, b;
    cin >> a >> b;
    if (a == 1 && b == 0 && n != 1) {
      cout << -1 << '\n';
      return 0;
    } else if (mp.count(a)) {
      if (mp[a] != b) {
        cout << -1 << '\n';
        return 0;
      }
    } else {
      mp[a] = b;
    }
  }
  int ans = 0;
  for (int i = 1; i <= n; ++i) {
    if (mp.count(i)) {
      ans += mp[i] * pow(10, n - i);
    } else if (i == 1 && !mp.count(i)) {
      ans += pow(10, n - i);
    }
  }
  cout << ans << '\n';
}
