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