#include <bits/stdc++.h>
using namespace std;
long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; }
long long lcm(long long a, long long b) { return b / gcd(a, b) * b; }
int main() {
  int n, m;
  cin >> n >> m;
  vector<int> s(m);
  vector<int> c(m);
  vector<int> a(n + 1);
  a[0] = 0;
  for (int i = 0; i < (m); i++) {
    cin >> s[i] >> c[i];
  }
  for (int i = 0; i < (m); i++) {
    if (s[i] == 1 && c[i] == 0 && n > 1) {
      cout << -1 << endl;
      return 0;
    } else if (s[i] == 1 && c[i] == 0 && n == 1) {
      cout << 0 << endl;
      return 0;
    }
    if (a[s[i]] == 0 || a[s[i]] == c[i]) {
      a[s[i]] = c[i];
    } else {
      cout << -1 << endl;
      return 0;
    }
  }
  if (a[1] == 0) a[1] = 1;
  int ans = 0;
  long long k = pow(10, n - 1);
  for (int i = 1; i <= n; i++) {
    ans += k * a[i];
    k /= 10;
  }
  cout << ans << endl;
  return 0;
}
