#include <bits/stdc++.h>
using namespace std;
int main() {
  int N, M;
  cin >> N >> M;
  vector<int> Num(N, -1);
  bool hasAns = true;
  for (int i = 0; i < M; i++) {
    int s, c;
    cin >> s >> c;
    if (Num[s - 1] >= 0 && Num[s - 1] != c) hasAns = false;
    if (s == 1 && c == 0)
      hasAns = false;
    else
      Num[s - 1] = c;
  }
  if (!hasAns) {
    cout << -1 << endl;
    return 0;
  }
  int ans = 0;
  if (Num[0] == -1) Num[0] = 1;
  for (int i = 0; i < N; i++) {
    ans *= 10;
    if (Num[i] > 0) ans += Num[i];
  }
  cout << ans << endl;
}
