#include <bits/stdc++.h>
using namespace std;
const int INF = int(1e9);
int main() {
  int N, M;
  cin >> N >> M;
  pair<int, int> A[M];
  for (int i = 0; i < (int)(M); i++) {
    cin >> A[i].first >> A[i].second;
  }
  sort(A, A + M);
  bool flg = true;
  int ans = 0;
  if (A[0].first != 1 || A[0].second == 0) flg = false;
  for (int i = 0; i < M - 1; ++i) {
    if (A[i].first == A[i + 1].first && A[i].second != A[i].second) {
      flg = false;
    }
  }
  int visited[N];
  for (int i = 0; i < (int)(N); i++) visited[i] = false;
  for (int i = 0; i < M; ++i) {
    if (!visited[A[i].first - 1]) {
      ans += int(pow(10.0, float(N - A[i].first)) * A[i].second);
      visited[A[i].first - 1] = true;
    }
  }
  if (flg)
    cout << ans;
  else
    cout << -1;
}
