#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  int n, m, s;
  char c;
  string num = "";
  cin >> n >> m;
  for (long long i = 0; i < n; i++) num.push_back('0');
  for (long long i = 0; i < m; i++) {
    cin >> s >> c;
    num[s - 1] = c;
  }
  if (n == 1 && num == "0") {
    cout << 0 << "\n";
    return 0;
  } else if (num[0] == '0')
    cout << -1 << "\n";
  else
    cout << num << "\n";
  return 0;
}
