#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m, a, k;
  string s;
  cin >> n >> m;
  vector<int> data(n, -1);
  bool flag = true;
  for (int i = 0; i < m; i++) {
    cin >> a;
    cin >> k;
    if (data.at(a - 1) != -1 && data.at(a - 1) != k) flag = false;
    data.at(a - 1) = k;
  }
  if (data.at(a - 1) == 0) flag = false;
  for (int i = 0; i < n; i++) {
    if (data.at(i) == -1) data.at(i) = 0;
  }
  if (flag) {
    for (int i = 0; i < n; i++) cout << data.at(i);
  } else
    cout << -1 << endl;
}
