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