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