#include <bits/stdc++.h>
using namespace std;
int main() {
  int arr[5];
  for (int i = 1; i <= 3; i++) {
    arr[i] = 10;
  }
  int n, m, a, b;
  cin >> n >> m;
  vector<int> v;
  for (int i = 1; i <= m; i++) {
    cin >> a >> b;
    arr[a] = b;
    if (a == 1) v.push_back(b);
  }
  sort(v.begin(), v.end());
  for (int i = 0; i < v.size(); i++) {
    if (v[i] > 0) {
      arr[1] = v[i];
      break;
    }
  }
  if (m == 0) {
    if (n == 1)
      cout << 0 << endl;
    else if (n == 2)
      cout << 10 << endl;
    else
      cout << 100 << endl;
    return 0;
  }
  if (n == 1) {
    if (arr[1] == 10)
      cout << 0 << endl;
    else
      cout << arr[1] << endl;
    return 0;
  }
  if (arr[1] == 0 || arr[1] == 10) {
    cout << -1 << endl;
    return 0;
  }
  cout << arr[1];
  if (n == 2) {
    if (arr[2] == 10)
      cout << 0;
    else
      cout << arr[2];
    return 0;
  }
  if (n == 3) {
    if (arr[2] == 10)
      cout << 0;
    else
      cout << arr[2];
    if (arr[3] == 10)
      cout << 0;
    else
      cout << arr[3];
    return 0;
  }
}
