#include <bits/stdc++.h>
using namespace std;
int N, M, answer[10];
int sub() {
  int S, C;
  for (int i = 0; i < M; ++i) {
    cin >> S >> C;
    if (answer[S - 1] == -1) {
      answer[S - 1] = C;
    } else if (answer[S - 1] != C) {
      return -1;
    }
  }
  return 0;
}
int main() {
  cin >> N >> M;
  for (int i = 0; i < N; ++i) {
    answer[i] = -1;
  }
  int real = sub();
  if (real == -1) {
    cout << "-1\n";
  } else if (real == 0) {
    for (int i = 0; i < N; ++i) {
      if (i == 0 && answer[i] == 0) {
        cout << "-1\n";
        return 0;
      } else if (i == 0) {
        cout << max(answer[i], 1);
      } else {
        cout << max(answer[i], 0);
      }
    }
    cout << endl;
  }
  return 0;
}
