#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  int *s, *c;
  int *num;
  cin >> n >> m;
  num = new int[n];
  for (int i = 0; i < n; ++i) {
    num[i] = 0;
  }
  s = new int[m];
  c = new int[m];
  for (int i; i < m; ++i) {
    cin >> s[i] >> c[i];
  }
  for (int i = 0; i < m; ++i) {
    if (num[s[i] - 1] == 0 || num[s[i] - 1] == c[i]) {
      num[s[i] - 1] = c[i];
    } else {
      cout << -1;
      delete[] s;
      delete[] c;
      delete[] num;
      return 0;
    }
  }
  if (num[0] == 0) {
    cout << -1;
  } else {
    for (int i = 0; i < n; ++i) {
      cout << num[i];
    }
  }
  delete[] s;
  delete[] c;
  delete[] num;
  return 0;
}
