#include <bits/stdc++.h>
using namespace std;
int main(void) {
  int n, m;
  cin >> n >> m;
  int num[n];
  bool filled[n], flag = true;
  memset(filled, 0, sizeof(filled));
  memset(num, 0, sizeof(num));
  int a[m][2];
  for (int i = 0; i < m; i++) {
    cin >> a[i][0] >> a[i][1];
    if (!filled[a[i][0] - 1]) {
      num[a[i][0] - 1] = a[i][1];
      filled[a[i][0] - 1] = true;
    } else {
      if (filled[a[i][0] - 1]) {
        if (a[i][1] != num[a[i][0] - 1]) flag = false;
      }
    }
  }
  if (!flag)
    cout << -1;
  else {
    for (int i = 0; i < n; i++) {
      if (i == 0 && num[i] == 0) continue;
      cout << num[i];
    }
  }
  cout << "\n";
  return 0;
}
