#include <bits/stdc++.h>
using std::cin;
using std::cout;
using namespace std;
long long gcd(long long a, long long b) {
  while (b != 0) {
    auto tmp = a;
    a = b;
    b = tmp % a;
  }
  return a;
}
long long lcm(long long a, long long b) { return (a * b) / gcd(a, b); }
int isPrime(int a) {
  for (int i = 2; i * i <= a; ++i) {
    if (a % i == 0) {
      return 0;
    }
  }
  return 1;
}
void oneCase() {
  int n, m;
  cin >> n >> m;
  vector<int> d(n);
  d[0] = 1;
  vector<bool> used(n);
  for (int i = 0; i < m; ++i) {
    int s, c;
    cin >> s >> c;
    --s;
    if (n > 1 && s == 0 && c == 0) {
      cout << -1 << "\n";
      return;
    }
    if (used[s] && d[s] != c) {
      cout << -1 << "\n";
      return;
    }
    if (!used[s]) {
      used[s] = true;
      d[s] = c;
    }
  }
  vector<int> degs = {1, 10, 100};
  int res = 0;
  for (int i = 0; i < n; ++i) {
    res += degs[i] * d[n - i - 1];
  }
  cout << res << "\n";
}
int main() {
  int t = 1;
  while (t > 0) {
    oneCase();
    --t;
  }
  return 0;
}
