#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 < M; i++) {
    cin >> s[i] >> c[i];
    s[i]--;
  }
  int digit[3] = {}, flag[3] = {}, ans = 0;
  for (int i = 0; i < M; i++) {
    if (flag[s[i]] && digit[s[i]] != c[i]) {
      cout << -1 << endl;
      return 0;
    } else if (s[i] == 0 && c[i] == 0) {
      cout << -1 << endl;
      return 0;
    } else {
      digit[s[i]] = c[i];
      flag[s[i]] = 1;
    }
  }
  if (flag[0] == 0 && N != 1) {
    digit[0] = 1;
  }
  for (int i = 0; i < N; i++) {
    ans += digit[N - i - 1] * pow(10, i);
  }
  cout << ans << endl;
  return 0;
}
