#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  int ar[n];
  for (int i = 0; i < n; i++) ar[i] = -1;
  for (int i = 0; i < m; i++) {
    int x, y;
    cin >> x >> y;
    x--;
    if (x == 0 && y == 0) {
      cout << -1 << endl;
      return 0;
    }
    if (ar[x] == y) {
      continue;
    }
    if (ar[x] != -1) {
      cout << -1 << endl;
      return 0;
    }
    ar[x] = y;
  }
  if (ar[0] == -1) {
    ar[0]++;
  }
  for (int i = 0; i < n; i++) {
    if (ar[i] == -1) {
      cout << 0;
    } else {
      cout << ar[i];
    }
  }
}
