#include <bits/stdc++.h>
using namespace std;
long long int gcd(long long int a, long long int b) {
  if (b == 0) return a;
  return gcd(b, a % b);
}
int main() {
  int N, M;
  cin >> N >> M;
  vector<vector<int>> SC(N, vector<int>(2));
  for (int i = 0; i < M; i++) {
    cin >> SC[i][0] >> SC[i][1];
  }
  vector<int> num(N, 10);
  bool hantei = true;
  for (int i = 0; i < M; i++) {
    if (num[SC[i][0] - 1] != SC[i][1]) {
      if (num[SC[i][0] - 1] == 10)
        num[SC[i][0] - 1] = SC[i][1];
      else {
        hantei = false;
        break;
      }
    }
  }
  if (hantei) {
    int ans = 0;
    for (int i = 0; i < N; i++) {
      if (num[i] == 10) {
        if (i == N)
          num[i] = 1;
        else
          num[i] = 0;
      }
      if (N - i == 3)
        ans += 100 * num[i];
      else if (N - i == 2)
        ans += 10 * num[i];
      else
        ans += num[i];
    }
    if (num[N - 1] == 0 && N > 2)
      cout << -1 << endl;
    else
      cout << ans << endl;
  } else
    cout << -1 << endl;
}
