#include <bits/stdc++.h>
using namespace std;
void YN(bool flg) {
  if (flg)
    cout << "YES" << endl;
  else
    cout << "NO" << endl;
}
void Yn(bool flg) {
  if (flg)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
}
void yn(bool flg) {
  if (flg)
    cout << "yes" << endl;
  else
    cout << "no" << endl;
}
int main() {
  int n, m;
  cin >> n >> m;
  string t = "";
  for (int i = 0; i < (int)(n); i++) t += '0';
  vector<int> check(4, 0);
  bool out = false;
  for (int i = 0; i < (int)(m); i++) {
    int s, c;
    cin >> s >> c;
    s--;
    if (check[s] != 0 && check[s] != c) {
      out = true;
    }
    check[s] = c;
    t[s] = c + '0';
  }
  if (n >= 2 && t[0] == '0') {
    out = true;
  }
  if (out == true)
    cout << -1 << endl;
  else
    cout << t << endl;
  return 0;
}
