#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m, f = 0, i, s, c;
  cin >> n >> m;
  int ar[n];
  for (i = 0; i < n; i++) ar[i] = -1;
  for (i = 0; i < m; i++) {
    cin >> s >> c;
    if (f) continue;
    if ((n > 1 && s == 1 && c == 0) || (ar[s - 1] != -1 && c != ar[s - 1]))
      f = 1;
    else
      ar[s - 1] = c;
  }
  if (f)
    cout << "-1\n";
  else {
    if (ar[0] == -1) cout << 1;
    for (i = 1; i < n; i++) cout << max(ar[i], 0);
  }
}
