#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vs = vector<string>;
template <typename T>
bool chmax(T& a, const T& b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
template <typename T>
bool chmin(T& a, const T& b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
int main() {
  int n, m, s;
  char c;
  cin >> n >> m;
  string str = "";
  for (int i = (int)(0); i < (int)(n); ++i) {
    str += "0";
  }
  for (int i = (int)(0); i < (int)(m); ++i) {
    cin >> s >> c;
    if (s == 1 && c == '0' && n != 1) {
      cout << "-1" << endl;
      return 0;
    } else {
      if (str[s - 1] != '0' && str[s - 1] != c) {
        cout << "-1" << endl;
        return 0;
      } else {
        str[s - 1] = c;
      }
    }
  }
  cout << str << endl;
  return 0;
}
