#include <bits/stdc++.h>
using namespace std;
int f(int a, int n) {
  if (n == 1) return a;
  f(a * 10, n - 1);
}
int main() {
  int N, M;
  cin >> N >> M;
  vector<pair<int, int>> s(M);
  vector<int> dig(N, -1);
  bool flag1 = true;
  for (int i = 0; i < M; i++) {
    cin >> s[i].first >> s[i].second;
  }
  for (int i = 0; i < M; i++) {
    if (dig[N - s[i].first] == -1) {
      dig[N - s[i].first] = s[i].second;
    } else if (dig[N - s[i].first] != s[i].second) {
      flag1 = false;
      break;
    }
  }
  if (dig[N - 1] == 0) flag1 = false;
  int ans = 0;
  for (int i = 0; i < N; i++) {
    if (dig[i] != -1) ans += f(dig[i], i + 1);
  }
  if (N == 3 && ans < 100) ans += 100;
  if (N == 2 && ans < 10) ans += 10;
  if (N == 1 && ans == 0) ans = 1;
  if (flag1) {
    cout << ans;
  } else {
    cout << "-1";
  }
}
