#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  int n, m, s, c;
  cin >> n >> m;
  int res[3] = {-1, -1, -1};
  for (int i = 0; i < m; i++) {
    cin >> s >> c;
    if (res[s - 1] == -1)
      res[s - 1] = c;
    else if (res[s - 1] != c) {
      cout << "-1\n";
      return 0;
    }
  }
  if (res[0] == 0) {
    cout << "-1\n";
    return 0;
  }
  if (res[0] == -1) res[0] = 1;
  for (int j = 0; j < n; j++) cout << (res[j] == -1 ? 0 : res[j]);
  cout << '\n';
  return 0;
}
