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