#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
int main() {
  int n, m, s, c;
  int a[3];
  fill(a, a + 3, -1);
  cin >> n >> m;
  while (m--) {
    cin >> s >> c;
    if (a[s - 1] >= 0 && a[s - 1] != c) {
      cout << -1 << endl;
      return 0;
    }
    a[s - 1] = c;
  }
  bool f = true;
  for (int i = 0; i < n; ++i) {
    if (f && a[i] < 0) continue;
    if (f && a[i] == 0 && i < n - 1) {
      cout << -1 << endl;
      return 0;
    }
    if (a[i] < 0) {
      cout << 0;
      continue;
    }
    cout << a[i];
    f = false;
  }
  if (f) cout << 0;
  cout << endl;
  return 0;
}
