#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  string ans(n, 'a');
  for (int i = 0; i < m; ++i) {
    int s, c;
    cin >> s >> c;
    if (c == 0 && s != n) {
      cout << "-1" << endl;
      return 0;
    }
    --s;
    if (ans[s] == 'a')
      ans[s] = '0' + c;
    else if (ans[s] != '0' + c) {
      cout << "-1" << endl;
      return 0;
    }
  }
  for (int i = 0; i < n; ++i) {
    if (ans[i] == 'a') ans[i] = '0';
  }
  cout << ans << endl;
  return 0;
}
