#include <bits/stdc++.h>
using namespace std;
int main() {
  int N;
  cin >> N;
  vector<int> ans(N, -1);
  int M;
  cin >> M;
  for (int i = 0; i < (M); ++i) {
    int a, b;
    cin >> a >> b;
    a--;
    if ((a == 0 && b == 0 && N != 1) || (ans[a] != b && ans[a] != -1)) {
      cout << -1 << endl;
      return 0;
    }
    ans[a] = b;
  }
  if (ans[0] == -1 && N != 0) ans[0] = 1;
  long long sum = 0;
  for (int i = 0; i < (N); ++i) {
    if (ans[i] == -1) continue;
    sum += ans[i] * pow(10, N - 1 - i);
  }
  cout << sum << endl;
  return 0;
}
