#include <bits/stdc++.h>
using namespace std;
vector<vector<int>> bingo(3, vector<int>(3));
int N, M;
int solve() {
  cin >> N;
  cin >> M;
  vector<int> si(M);
  vector<int> ci(M);
  for (int i = 0; i < M; i++) {
    cin >> si[i];
    cin >> ci[i];
  }
  for (int i = 0; i < M; i++) {
    for (int j = 0; j < M; j++) {
      if (si[i] == si[j]) {
        if (ci[i] != ci[j]) {
          cout << -1;
          return 0;
        }
      }
    }
  }
  for (int i = 0; i < M; i++) {
    if (si[i] == 1) {
      if (ci[i] == 0) {
        cout << -1;
        return 0;
      }
    }
  }
  int ans;
  vector<int> already(M);
  for (int i = 0; i < M; i++) {
    if (already[si[i] - 1] == 0) {
      ans += ci[i] * pow(10, N - si[i]);
      already[si[i] - 1] = 1;
    }
  }
  if (already[0] == 0) {
    ans += pow(10, N - 1);
  }
  cout << ans;
  return 0;
}
int main() {
  solve();
  return 0;
}
