#include <bits/stdc++.h>
using namespace std;
int main(int argc, char **argv) {
  int i;
  int N, M;
  cin >> N >> M;
  vector<int> X(N, -1);
  bool unable = false;
  int s, c;
  for (int i = 0; i < M; ++i) {
    cin >> s >> c;
    --s;
    if (X[s] == -1 || X[s] == c)
      X[s] = c;
    else
      unable = true;
  }
  if (N > 1 && X[0] == 0) unable = true;
  if (!unable) {
    for (int i = 0; i < N; ++i) {
      if (X[i] == -1) {
        if (i == 0 && M > 1) {
          X[i] = 1;
        } else {
          X[i] = 0;
        }
      }
      cout << X[i];
    }
  } else {
    cout << -1;
  }
  cout << endl;
  return 0;
}
