#include <bits/stdc++.h>
using namespace std;
int main(void) {
  int N, M;
  cin >> N >> M;
  vector<int> s(M), c(M);
  for (int i = 0; i < M; i++) cin >> s[i] >> c[i];
  for (int i = 0; i < M; i++) s[i]--;
  const char init = '*';
  string ans(N, init);
  for (int i = 0; i < M; i++) {
    int index = s[i];
    char ch = c[i] + '0';
    if (ans[index] == init)
      ans[index] = ch;
    else if (ans[index] != ch) {
      cout << -1 << endl;
      return 0;
    }
  }
  for (int i = 0; i < N; i++) {
    if (ans[i] == init) ans[i] = '0';
  }
  if (N > 1) {
    if (ans[0] == '0') {
      cout << -1 << endl;
      return 0;
    }
    cout << ans << endl;
  } else {
    cout << ans << endl;
  }
  return 0;
}
