#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m, i, j, a, b;
  cin >> n >> m;
  bool check = 0;
  int num[n + 1];
  memset(num, -1, (n + 1) * sizeof(int));
  for (i = 0; i < m; i++) {
    cin >> a >> b;
    if (num[a] == -1)
      num[a] = b;
    else if (num[a] != b)
      check = 1;
  }
  if (num[1] == -1) num[1] = 1;
  for (i = 1; i <= n; i++) {
    if (i == 1 && num[i] == 0) {
      check = 1;
      break;
    }
    if (num[i] == -1) num[i] = 0;
  }
  for (i = 1; i <= n; i++) {
    if (check) {
      cout << "-1";
      break;
    }
    cout << num[i];
  }
}
