#include <bits/stdc++.h>
using namespace std;
int main(void) {
  int N, M;
  cin >> N >> M;
  vector<int> d(N + 1, -1);
  for (int i = 0; i < M; i++) {
    int s, c;
    cin >> s >> c;
    if (d[s] == -1 || d[s] == c)
      d[s] = c;
    else {
      cout << -1 << endl;
      return 0;
    }
    if (s == 1 && c == 0) {
      cout << -1 << endl;
      return 0;
    }
  }
  if (d[1] == -1) d[1] = 1;
  for (int i = 1; i <= N; i++) {
    if (d[i] == -1)
      cout << 0;
    else
      cout << d[i];
  }
  cout << endl;
  return 0;
}
