#include <bits/stdc++.h>
using namespace std;
int main(void) {
  int n, m;
  cin >> n >> m;
  int s[m], c[m];
  for (int i = 0; i < m; i++) cin >> s[i] >> c[i];
  bool check = true;
  int a[n];
  for (int i = 0; i < n; i++) {
    int b = 0;
    for (int j = 0; j < m; j++) {
      if (i + 1 == s[j]) {
        if (b != 0 && b != c[j])
          check = false;
        else
          b = c[j];
      }
    }
    if (!check || (m == 1 && c[0] == 0)) {
      check = false;
      cout << -1 << endl;
      break;
    } else {
      if (i == 0 && b == 0)
        a[i] = 1;
      else
        a[i] = b;
    }
  }
  if (check) {
    for (int i = 0; i < (n); i++) cout << a[i];
  }
}
