#include <bits/stdc++.h>
using namespace std;
bool check_prime(long long n) {
  long long flag = 0;
  for (long long i = 2; i * i <= n; i++) {
    if (n % i == 0) {
      flag = 1;
      break;
    }
  }
  if (n == 1)
    return false;
  else if (flag == 0 || n == 2 || n == 3) {
    return true;
  } else {
    return false;
  }
}
long long BE(long long x, long long n, long long m) {
  long long result = 1;
  while (n > 0) {
    if (n % 2 == 1) result = result * x % m;
    x = x * x % m;
    n = n / 2;
  }
  return result;
}
int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(0);
  long long n, m;
  cin >> n >> m;
  long long s[m];
  long long c[m];
  for (long long i = 0; i < m; i++) cin >> s[i] >> c[i];
  long long flag = 0;
  map<long long, long long> mt;
  vector<long long> ch(n);
  for (long long i = 0; i < n; i++) {
    ch[i] = 0;
  }
  for (long long i = 0; i < m; i++) {
    long long x = mt[s[i]];
    if (s[i] > n) {
      flag = 1;
      break;
    } else if (s[i] == 1 && c[i] == 0) {
      flag = 1;
      break;
    } else if (mt[s[i]] == 0) {
      mt[s[i]] = c[i];
      ch[s[i] - 1] = (c[i]);
    } else if (x != c[i]) {
      flag = 1;
      break;
    }
  }
  if (ch[0] == 0 && n > 1) {
    ch[0] = 1;
  } else if (ch[0] == 0 && n == 1) {
    ch[0] = 0;
  }
  if (flag == 1) {
    cout << -1 << '\n';
  } else {
    for (long long i = 0; i < n; i++) {
      cout << ch[i];
    }
    cout << '\n';
  }
  return 0;
}
