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