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