#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  vector<int> ans(n, -1);
  for (auto i = 0; i < m; i++) {
    int s, c;
    cin >> s >> c;
    s--;
    if (ans[s] == -1 or ans[s] == c)
      ans[s] = c;
    else {
      cout << -1 << endl;
      return 0;
    }
  }
  if (ans[n - 1] == -1 and n > 1) {
    cout << -1 << endl;
    return 0;
  }
  for (auto i = 0; i < n; i++) cout << ((ans[i] == -1) ? 0 : ans[i]);
  cout << endl;
  return 0;
}
