#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  vector<pair<bool, int>> ans(n);
  for (int i = 0; i < m; i++) {
    int s, c;
    cin >> s >> c;
    s--;
    if (!ans[s].first) {
      ans[s].first = true;
      ans[s].second = c;
    } else if (ans[s].second == c)
      continue;
    else {
      cout << -1 << endl;
      return 0;
    }
  }
  if (ans[0].second == 0 && n != 1) {
    cout << -1 << endl;
    return 0;
  }
  for (int i = 0; i < n; i++) {
    cout << ans[i].second;
  }
  cout << endl;
}
