#include <bits/stdc++.h>
using namespace std;
int main() {
  int N, M;
  cin >> N >> M;
  vector<int> s(M, 0);
  vector<int> c(M, 0);
  for (int i = 0; i < M; i++) {
    cin >> s[i] >> c[i];
  }
  for (int i = 0; i < M; i++) {
    for (int j = i + 1; j < M; j++) {
      if (s[i] == s[j] && c[i] != c[j]) {
        cout << -1;
        return 0;
      }
    }
  }
  vector<int> A(5, 0);
  int count[5];
  for (int i = 0; i < M; i++) {
    if (s[i] == 1) {
      A[0] = c[i];
      count[0] = 1;
    }
    if (s[i] == 2) {
      A[1] = c[i];
      count[1] = 1;
    }
    if (s[i] == 3) {
      A[2] = c[i];
      count[2] = 1;
    }
    if (s[i] == 4) {
      A[3] = c[i];
      count[3] = 1;
    }
    if (s[i] == 5) {
      A[4] = c[i];
      count[4] = 1;
    }
  }
  if (A[0] == 0 && A[1] == 0 && A[2] == 0 && A[3] == 0 && A[4] == 0) {
    cout << -1;
    return 0;
  }
  if (A[0] == 0) {
    cout << -1;
    return 0;
  }
  int keta;
  for (int i = 4; i > -1; i--) {
    if (count[i] == 1) {
      keta = i + 1;
      break;
    }
  }
  int ans = 0;
  for (int i = keta; i > -1; i--) {
    ans = ans + A[i - 1] * pow(10, keta - i);
  }
  cout << ans;
  return 0;
}
