#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  int s[m];
  char c[m];
  for (int i = 0; i < (m); i++) {
    cin >> s[i] >> c[i];
  }
  string a;
  for (int i = 0; i < (n); i++) {
    a.push_back('0');
  }
  bool ok = true;
  for (int i = 0; i < (m); i++) {
    a[s[i] - 1] = c[i];
  }
  for (int i = 0; i < (m); i++) {
    if (a[s[i] - 1] != c[i]) {
      ok = false;
    }
  }
  if (s[0] == '0') {
    ok = false;
  }
  stringstream ss;
  int aa;
  ss << a;
  ss >> aa;
  if (aa < pow(10, n - 1)) {
    ok = false;
  }
  if (ok) {
    cout << a << endl;
  } else {
    cout << "-1" << endl;
  }
}
