#include <bits/stdc++.h>
using namespace std;
int main() {
  int N, M;
  cin >> N >> M;
  map<int, int> table;
  for (int i = 0; i < (int)M; i++) {
    int a, b;
    cin >> a >> b;
    if (table.count(a)) {
      if (table[a] == b) {
        continue;
      }
      table[1] = 0;
      break;
    }
    table[a] = b;
  }
  if (M == 0)
    cout << 0 << endl;
  else if (!table.count(1))
    table[1] = 1;
  else if (table[1] == 0) {
    if (N == 1) {
      cout << 0 << endl;
    } else
      cout << -1 << endl;
  } else if (N == 1)
    cout << table[1] << endl;
  else if (N == 2)
    cout << table[1] * 10 + table[2] << endl;
  else
    cout << table[1] * 100 + table[2] * 2 + table[3] << endl;
}
