#include <bits/stdc++.h>
using namespace std;
long long gcd(long long a, long long b) {
  if (a % b == 0) {
    return b;
  } else
    return gcd(b, a % b);
}
long long lcm(long long a, long long b) {
  if (a == 0) {
    return b;
  }
  return a / gcd(a, b) * b;
}
template <class T>
long long LBI(vector<T>& ar, T in) {
  return lower_bound(ar.begin(), ar.end(), in) - ar.begin();
}
template <class T>
long long UBI(vector<T>& ar, T in) {
  return upper_bound(ar.begin(), ar.end(), in) - ar.begin();
}
long long n, m, s, c, ans = 0, memo[3] = {};
bool flag = false;
int main() {
  cin >> n >> m;
  ans = pow(10, n - 1);
  for (int i = 0; i < (3); ++i) memo[i] = -1;
  for (int i = 0; i < (m); ++i) {
    cin >> s >> c;
    if ((memo[s - 1] != -1 && memo[s - 1] != c) ||
        (s == 1 && c == 0 && n != 1)) {
      cout << -1 << endl;
      return 0;
    }
    if (!flag && memo[s - 1] == -1) {
      if (s == 1) {
        ans += (c - 1) * pow(10, n - 1);
        memo[0] = c;
      } else {
        ans += c * pow(10, n - s);
        memo[s - 1] = c;
      }
    }
    if (n == 1 && s == 1 && c == 0) {
      flag = true;
      ans = 0;
    }
  }
  cout << ans << endl;
  return 0;
}
