#include <bits/stdc++.h>
using namespace std;
const long long kMod = 1e9 + 7;
__int32_t main() {
  ios::sync_with_stdio(false);
  long long n, m;
  cin >> n >> m;
  vector<long long> s(m), c(m);
  for (__int32_t(i) = 0; (i) < (m); ++(i)) {
    cin >> s[i] >> c[i];
  }
  vector<long long> mem(3, -1);
  for (__int32_t(i) = 0; (i) < (m); ++(i)) {
    if (mem[s[i] - 1] == -1) {
      if (n >= 2 && s[i] == n && !c[i]) {
        cout << -1;
        return 0;
      } else {
        mem[s[i] - 1] = c[i];
      }
    } else if (mem[s[i] - 1] != c[i]) {
      cout << -1;
      return 0;
    }
  }
  for (__int32_t(i) = 0; (i) < (n); ++(i)) {
    if (mem[i] == -1) {
      cout << 0;
    } else {
      cout << mem[i];
    }
  }
  return 0;
}
