#include <bits/stdc++.h>
using namespace std;
void solve(int N, int M, std::vector<int> s, std::vector<int> c) {
  vector<bool> check(N, false);
  vector<int> num(N, 0);
  for (int i = 0; i < M; i++) {
    if (check[s[i] - 1] && num[s[i] - 1] != c[i]) {
      cout << -1 << endl;
      return;
    }
    num[s[i] - 1] = c[i];
    check[s[i] - 1] = true;
  }
  if (1 < N && num[0] == 0) {
    cout << -1 << endl;
    return;
  }
  if (num[0] == 0) {
    num[0] = 1;
  }
  for (int i = 0; i < N; i++) {
    cout << num[i];
  }
}
int main() {
  int N;
  scanf("%d", &N);
  int M;
  scanf("%d", &M);
  std::vector<int> s(M);
  std::vector<int> c(M);
  for (int i = 0; i < M; i++) {
    scanf("%d", &s[i]);
    scanf("%d", &c[i]);
  }
  solve(N, M, std::move(s), std::move(c));
  return 0;
}
