#include <bits/stdc++.h>
using namespace std;
int main() {
  int N, M;
  cin >> N >> M;
  int ans = -1;
  vector<int> V(N + 1, -1);
  bool flag = true;
  for (int i = 0; i < M; i++) {
    int S, C;
    cin >> S >> C;
    if (V[S] == -1)
      V[S] = C;
    else if (V[S] != C)
      flag = false;
  }
  if (flag) {
    if (N == 1)
      ans = V[1];
    else if (N == 2) {
      if (V[1] > 0) ans = 10 * V[1] + max(0, V[2]);
    } else {
      if (V[1] > 0) ans = 100 * V[1] + 10 * max(0, V[2]) + max(0, V[3]);
    }
  }
  cout << ans << endl;
}
