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