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