#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  int digit[9];
  memset(digit, 0, sizeof(digit));
  bool flag = false;
  vector<int> v(n);
  for (int i = 0; i < n; i++) {
    if (i == 0) {
      v[i] = 1;
    } else {
      v[i] = 0;
    }
  }
  for (int i = 0; i < m; i++) {
    int a, b;
    cin >> a >> b;
    if (digit[a] != 0) {
      if (v[a - 1] != b) {
        flag = true;
      }
    } else {
      v[a - 1] = (b);
    }
    digit[a]++;
    if (a == 1 && b == 0) {
      if (n != 1) {
        flag = true;
      }
    }
  }
  if (flag) {
    cout << -1 << endl;
    return 0;
  }
  for (auto x : v) {
    cout << x;
  }
  cout << endl;
  return 0;
}
