#include <bits/stdc++.h>
using namespace std;
void yn(bool b) {
  if (b)
    printf("yes\n");
  else
    printf("no\n");
}
void Yn(bool b) {
  if (b)
    printf("Yes\n");
  else
    printf("No\n");
}
void YN(bool b) {
  if (b)
    printf("YES\n");
  else
    printf("NO\n");
}
int main() {
  int N, M;
  cin >> N >> M;
  vector<int> s(M);
  vector<int> c(M);
  for (int i = 0; i < M; i++) cin >> s[i] >> c[i];
  vector<int> num(N, -1);
  int ans = 0;
  for (int i = 0; i < M; i++) {
    if (num[s[i] - 1] != -1 && num[s[i] - 1] != c[i]) {
      ans = -1;
      break;
    } else
      num[s[i] - 1] = c[i];
  }
  if (ans == 0) {
    if (num[0] == -1) num[0] = 1;
    for (int i = 0; i < N; i++) {
      if (num[i] == -1) num[i] = 0;
    }
    for (int i = 0; i < N; i++) {
      ans = ans + pow(10, N - 1 - i) * num[i];
    }
  }
  if (N > 1 && num[0] == 0) ans = -1;
  cout << ans;
}
