#include <bits/stdc++.h>
using namespace std;
int main() {
  int N, M;
  cin >> N >> M;
  vector<int> v(N + 1, -1);
  bool err = false;
  for (int i = 0; i < M; i++) {
    int s, c;
    cin >> s >> c;
    if (v[s] != -1 && v[s] != c) {
      err = true;
      break;
    }
    v[s] = c;
  }
  if (v[1] == 0) {
    err = true;
  } else if (v[1] == -1) {
    if (N > 1)
      v[1] = 1;
    else
      v[1] = 0;
  }
  if (err != true) {
    for (int i = 1; i <= N; i++) {
      if (v[i] == -1) {
        v[i] = 0;
      }
      cout << v[i];
    }
  } else {
    cout << -1;
  }
}
