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