#include <bits/stdc++.h>
using namespace std;
const long long inf = 1e12 + 57;
signed main() {
  long long n, m;
  cin >> n >> m;
  vector<long long> a(n, -1);
  for (long long i = 0; i < m; ++i) {
    long long x, y;
    cin >> x >> y;
    --x;
    if (a[x] != y && a[x] != -1) {
      cout << -1;
      return 0;
    }
    a[x] = y;
  }
  if (a[0] == -1)
    a[0] = 1;
  else if (a[0] == 0) {
    cout << -1;
    return 0;
  }
  for (long long i : a) {
    if (i == -1) {
      cout << 0;
    } else {
      cout << i;
    }
  }
}
