#include <bits/stdc++.h>
using namespace std;
int main() {
  int N, M;
  cin >> N >> M;
  int s[M], c[M], num[N], hantei = 1, ans = 0;
  for (int i = 0; i < N; i++) {
    num[i] = -1;
  }
  for (int i = 0; i < M; i++) {
    cin >> s[i] >> c[i];
    if (num[i] == -1)
      num[s[i] - 1] = c[i];
    else if (num[s[i] - 1] != c[i])
      hantei = -1;
    if (N >= 2) {
      if (s[i] == 1 && c[i] == 0) hantei = -1;
    }
  }
  for (int i = 0; i < N; i++) {
    if (num[i] == -1) {
      if (i == 0)
        num[0] = 1;
      else
        num[i] = 0;
    }
    ans += pow(10, N - i - 1) * num[i];
  }
  if (hantei == -1)
    cout << "-1" << endl;
  else
    cout << ans << endl;
}
