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