#include <bits/stdc++.h>
using namespace std;
int main() {
  int N, M;
  cin >> N >> M;
  vector<int> s(N + 1, -9);
  for (int i = 0; i < M; i++) {
    int index = 0;
    int c = 0;
    int TMP = -9;
    cin >> index;
    cin >> c;
    TMP = s.at(index);
    if (TMP != -9 && c != TMP) {
      cout << -1 << endl;
      return 0;
    }
    s.at(index) = c;
  }
  if (N == 1 && s.at(1) == 0) {
    cout << 0 << endl;
    return 0;
  }
  if (N > 1 && s.at(1) == 0) {
    cout << -1 << endl;
    return 0;
  }
  if (M == 0 && N == 1) {
    cout << 0 << endl;
    return 0;
  }
  if (M == 0 && N > 1) {
    cout << -1 << endl;
    return 0;
  } else {
    for (int i = 1; i <= N; i++) {
      if (s.at(i) == -9) {
        cout << 0;
      } else {
        cout << s.at(i);
      }
    }
    cout << endl;
  }
}
