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