#include <bits/stdc++.h>
using namespace std;
int gcd(int a, int b) { return (a % b == 0 ? b : gcd(b, a % b)); }
int64_t lcm(int a, int b) { return (int64_t)a * b / gcd(a, b); }
int factorial(int a) {
  int b = 1;
  while (a) {
    b *= a--;
  }
  return b;
}
bool is_prime(int a) {
  if (a <= 1) return false;
  for (int i = 2; (int64_t)i * i <= a; i++) {
    if (a % i == 0) return false;
  }
  return true;
}
int get_adp(double x, int n) {
  return (int)round((x - (int)x) * pow(10, n)) % 10;
}
int main() {
  int n, m, s, c, ans = 0, ndigits;
  bool flag = true, zero_flag = false;
  cin >> n >> m;
  for (int i = 0; i < m; i++) {
    cin >> s >> c;
    if (n > s && ans < pow(10, n - s)) {
      ans += c * pow(10, n - s);
    } else if (s == n && c != 0 && !zero_flag && (ans % 10 == 0))
      ans += c;
    else if (s == n && c == 0 && (ans % 10 == 0))
      zero_flag = true;
    else {
      ndigits = (int)pow(10, n - s);
      if (c != (ans / ndigits) % 10) flag = false;
      ans = ans - ((ans / ndigits) % 10) * ndigits + c * ndigits;
    }
  }
  if (zero_flag && (ans % 10 != 0)) flag = false;
  if (ans < (int)pow(10, n - 1) || (ans == 0 && n != 1)) flag = false;
  cout << (flag ? ans : -1) << endl;
}
