#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;
  if (m == 0)
    cout << 0 << endl;
  else {
    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;
    }
    for (int i = 0; i < (int)(n); i++)
      if (s[i] == ' ') s.replace(i, 1, "0");
    if (s[0] == '0') ans = false;
    if (s == "0")
      ans = true;
    else if (s[0] == '0')
      s.replace(0, 1, "1");
    cout << (ans ? s : "-1") << endl;
  }
  return 0;
}
