#include <bits/stdc++.h>
using namespace std;
int main() {
  int N, M;
  vector<int> digit(N);
  cin >> N >> M;
  int s, c;
  bool a = false;
  int ans = 0;
  for (int i = 0; i < M; i++) {
    cin >> s >> c;
    if (s == 1 && c == 0) {
      a = true;
      break;
    }
    if (digit[s - 1] != 0 && digit[s - 1] != c + 1) {
      a = true;
      break;
    } else {
      digit[s - 1] = c + 1;
    }
  }
  if (a) {
    cout << -1 << endl;
  } else {
    for (int i = 1; i < N; i++) {
      int base = max(0, digit[i] - 1);
      for (int j = 0; j < N - 1 - i; j++) {
        base = base * 10;
      }
      ans += base;
    }
    int top = max(1, digit[0] - 1);
    for (int j = 0; j < N - 1; j++) {
      top = top * 10;
    }
    ans += top;
  }
}
