#include <bits/stdc++.h>
using namespace std;
const long long mod = 1e9 + 7;
const long long oo = 1e9 + 10;
const int Max = 1e6 + 10;
long long powmod(long long a, long long b) {
  long long res = 1;
  a %= mod;
  assert(b >= 0);
  for (; b; b >>= 1) {
    if (b & 1) res = res * a % mod;
    a = a * a % mod;
  }
  return res;
}
long long a[10] = {0};
long long f[10] = {0};
long long s, c;
void solve() {
  long long n, m;
  cin >> n >> m;
  for (int i = 0; i < m; i++) {
    cin >> s >> c;
    s--;
    if (f[s] == 0) {
      a[s] = c;
      f[s] = 1;
    } else {
      if (a[s] != c) {
        cout << -1;
        return;
      }
    }
  }
  if (f[0] == 0) a[0] = 1;
  if (a[0] == 0 && n > 1) {
    cout << -1;
  } else {
    for (int i = 0; i < n; i++) cout << a[i];
  }
}
int main() {
  ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  solve();
  return 0;
}
