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