#include <bits/stdc++.h>
using namespace std;
long long mo = 1e9 + 7;
int main() {
  int N, M;
  cin >> N >> M;
  vector<int> s(M);
  vector<int> c(M);
  vector<int> t(N, -1);
  for (int i = 0; i < M; i++) {
    cin >> s[i] >> c[i];
  }
  for (int i = 0; i < M; i++) {
    if (s[i] == 1 && c[i] == 0) {
      cout << -1 << endl;
      return 0;
    }
  }
  bool ok = true;
  for (int i = 0; i < M; i++) {
    if (t[s[i] - 1] == -1) {
      t[s[i] - 1] = c[i];
    } else {
      if (t[s[i] - 1] != c[i]) {
        ok = false;
      }
    }
  }
  if (!ok) {
    cout << -1 << endl;
    return 0;
  }
  for (int i = 0; i < N; i++) {
    if (t[i] != -1) {
      cout << t[i];
    } else if (i != 0) {
      cout << 0;
    } else {
      cout << 1;
    }
  }
  cout << endl;
}
