#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  vector<int> out(n, -1);
  for (int i = 0; i < m; i++) {
    int s, c;
    cin >> s >> c;
    s--;
    if (out.at(s) != -1) {
      if (out.at(s) != c) {
        cout << -1;
        return 0;
      }
    }
    out.at(s) = c;
  }
  if (out.at(n - 1) == -1) {
    cout << -1;
    return 0;
  }
  for (int i = 0; i < n; i++) {
    if (out.at(i) == -1) out.at(i) = 0;
    cout << out.at(i);
  }
}
