#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  int n, m;
  cin >> n >> m;
  char d[4] = {};
  for (int i = 0; i < (int)(3); i++) d[i] = '\0';
  for (int i = 0; i < (int)(m); i++) {
    int s;
    char c;
    cin >> s;
    cin.ignore();
    cin >> c;
    s--;
    if (d[s] != '\0' && d[s] != c) {
      cout << -1 << endl;
      return 0;
    }
    if (n != 1 && s == 0 && c == '0') {
      cout << -1 << endl;
      return 0;
    }
    d[s] = c;
  }
  if (n != 1 && d[0] == '\0') d[0] = 1;
  for (int i = 0; i < (int)(3); i++)
    if (d[i] == '\0') d[i] = '0';
  cout << d << endl;
  return 0;
}
