#include <bits/stdc++.h>
using namespace std;
const long long mod = 1e9 + 7;
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
unsigned long long gcd(unsigned long long a, unsigned long long b) {
  return b ? gcd(b, a % b) : a;
}
unsigned long long lcm(unsigned long long a, unsigned long long b) {
  return a / gcd(a, b) * b;
}
int main() {
  int n, m;
  cin >> n >> m;
  vector<int> s(m), c(m);
  for (int i = 0, i_len = (m); i < i_len; i++) {
    cin >> s[i] >> c[i];
    s[i]--;
  }
  vector<int> q(n, -1);
  for (int i = 0, i_len = (m); i < i_len; i++) {
    if (q[s[i]] != -1 && q[s[i]] != c[i]) {
      cout << -1 << endl;
      return 0;
    } else
      q[s[i]] = c[i];
  }
  if (q[0] == 0) {
    cout << -1 << endl;
    return 0;
  }
  int b = 1, e = 10;
  for (int i = 0, i_len = (n - 1); i < i_len; i++) {
    b *= 10;
    e *= 10;
  }
  if (n == 1) b = 0;
  for (int i = b; i < e; ++i) {
    int i2 = i;
    bool ok = true;
    for (int j = ((int)(n)-1); j >= 0; j--) {
      if (q[j] != -1 && i2 % 10 != q[j]) ok = false;
      i2 /= 10;
    }
    if (ok) {
      cout << i << endl;
      return 0;
    }
  }
  cout << -1 << endl;
  return 0;
}
