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