#include <bits/stdc++.h>
template <class T>
bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T>
bool chmin(T &a, const T &b) {
  if (b < a) {
    a = b;
    return 1;
  }
  return 0;
}
using namespace std;
int main() {
  int n, m;
  string s = "";
  int place;
  string added;
  cin >> n >> m;
  for (int i = 0; i < (int)(n); i++) s += " ";
  bool ans = true;
  while (m--) {
    cin >> place;
    cin >> added;
    if (s[place - 1] == ' ' || s[place - 1] == added[0])
      s.replace(place - 1, 1, added);
    else
      ans = false;
  }
  if (s[0] == '0') ans = false;
  if (s == "0") ans = true;
  for (int i = 0; i < (int)(n); i++)
    if (s[i] == ' ') s.replace(i, 1, "0");
  cout << (ans ? s : "-1") << endl;
  return 0;
}
