#include <bits/stdc++.h>
using namespace std;
template <typename T>
inline T gcd(T a, T b) {
  if (b) return gcd(b, a % b);
  return a;
}
template <typename T>
inline T ext_gcd(T a, T b, T& x, T& y) {
  if (a == 0) {
    x = 0;
    y = 1;
    return b;
  }
  T x1, y1;
  T g = ext_gcd(b % a, a, x1, y1);
  x = y1 - (b / a) * x1;
  y = x1;
  return g;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  long long n, m;
  cin >> n >> m;
  vector<long long> nums(n, -1);
  bool works = true;
  for (long long(i) = 0; i < m; i++) {
    long long s, c;
    cin >> s >> c;
    if (nums[s - 1] != -1 && nums[s - 1] != c) works = false;
    nums[s - 1] = c;
  }
  if (nums[0] == -1) nums[0] = 1;
  if (nums[0] == 0) works = false;
  if (works) {
    for (auto(i) : nums) {
      if (i == -1)
        cout << 0;
      else
        cout << i;
    }
    cout << '\n';
  } else
    cout << -1 << '\n';
}
