#include <bits/stdc++.h>
using namespace std;
using lint = long long int;
void leave(string message) {
  cout << message << endl;
  exit(0);
}
int main() {
  lint n, m;
  cin >> n >> m;
  string num = "000";
  for (lint i = 0; i < m; i++) {
    lint s;
    char c;
    cin >> s >> c;
    if (num[s - 1] != '0' && num[s - 1] != c) leave("-1");
    num[s - 1] = c;
  }
  num = "0" + num;
  string ans = to_string(stoi(num));
  if (ans.length() != n) leave("-1");
  cout << ans << endl;
}
