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