#include <bits/stdc++.h>
using namespace std;
template <class T>
inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T>
inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
const long long INF = 1LL << 60;
vector<pair<long long int, long long int> > p;
bool pairCompare(const pair<double, long long int>& firstElof,
                 const pair<double, long long int>& secondElof) {
  return firstElof.first < secondElof.first;
}
bool x[1000100];
long long int num[1000100];
long long int fibl[1000100] = {0};
long long int fib(long long int a) {
  if (fibl[a] != 0) return fibl[a];
  if (a == 0) {
    return 0;
  } else if (a == 1) {
    return 1;
  }
  return fibl[a] = fib(a - 1) + fib(a - 2);
}
long long int eratosthenes(long long int n) {
  int p = 0;
  for (long long int i = 0; i <= n; ++i) x[i] = true;
  x[0] = x[1] = false;
  for (int i = 2; i <= n; ++i) {
    if (x[i]) {
      p++;
      for (int j = 2 * i; j <= n; j += i) x[j] = false;
    }
    num[i] = p;
  }
  return p;
}
long long int gcd(long long int a, long long int b) {
  if (a % b == 0)
    return (b);
  else
    return (gcd(b, a % b));
}
long long int keta(long long int N) {
  int tmp{};
  while (N > 0) {
    tmp += (N % 10);
    N /= 10;
  }
  N = tmp;
  return N;
}
int main() {
  long long int n, m;
  cin >> n >> m;
  bool z[n];
  long long int ansl[n];
  fill(z, z + n, false);
  for (long long int i = 0; i < m; i++) {
    long long int s, c;
    cin >> s >> c;
    if (z[s - 1]) {
      if (ansl[s - 1] == c) continue;
      cout << -1 << endl;
      return 0;
    }
    ansl[s - 1] = c;
    z[s - 1] = true;
  }
  if (z[0] and ansl[0] == 0) {
    cout << -1 << endl;
    return 0;
  }
  long long int ans = 0, flag = 1;
  for (long long int i = 0; i < n; i++) {
    if (z[n - 1 - i]) {
      ans += ansl[n - 1 - i] * flag;
    }
    flag *= 10;
  }
  if (ans == 0) {
    ans += flag / 10;
  }
  cout << ans << endl;
}
