#include <bits/stdc++.h>
using namespace std;
long long int power(long long int x, unsigned long long int y) {
  long long int res = 1;
  while (y > 0) {
    if (y & 1) {
      res = res * x;
    }
    y = y >> 1;
    x = x * x;
  }
  return res;
}
long long int powermod(long long int x, unsigned long long int y,
                       long long int p) {
  long long int res = 1;
  x = x % p;
  while (y > 0) {
    if (y & 1) {
      res = (res * x) % p;
    }
    y = y >> 1;
    x = (x * x) % p;
  }
  return res;
}
int32_t main() {
  long long int n, m;
  cin >> n >> m;
  vector<long long int> v(n, -1);
  long long int ok = 1;
  while (m--) {
    long long int s, c;
    cin >> s >> c;
    if (s == 1 and c == 0) ok = 0;
    if (v[s - 1] != c and v[s - 1] != -1) ok = 0;
    v[s - 1] = c;
  }
  if (v[0] == -1) v[0] = 1;
  if (ok)
    for (long long int i = (long long int)(0); i < (long long int)(n); i++)
      cout << (v[i] == -1 ? 0 : v[i]);
  else
    cout << -1 << "\n";
  return 0;
}
