#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  vector<int> s(m);
  vector<int> c(m);
  for (int i = 0; i < m; i++) cin >> s[i] >> c[i];
  for (int i = 0; i < m; i++) {
    for (int j = 0; j < m; j++) {
      if (i != j && s[i] == s[j] && c[i] != c[j]) {
        cout << -1 << endl;
        return 0;
      }
    }
  }
  if (n == 1) {
    if (m == 0)
      cout << 0 << endl;
    else
      cout << c[0] << endl;
  } else if (n == 2) {
    int sum = 0;
    for (int i = 0; i < m; i++) {
      if (s[i] == 1 && sum / 10 != c[i])
        sum += c[i] * 10;
      else if (s[i] == 2 && sum - (sum / 10) * 10 != c[i])
        sum += c[i];
    }
    if (sum / 10 == 0)
      cout << sum + 10 << endl;
    else
      cout << sum << endl;
  } else if (n == 3) {
    int sum = 0;
    for (int i = 0; i < m; i++) {
      if (s[i] == 1 && sum / 100 != c[i])
        sum += c[i] * 100;
      else if (s[i] == 2 && (sum - (sum / 100) * 100) / 10 != c[i])
        sum += c[i] * 10;
      else if (s[i] == 3 && sum - (sum / 10) * 10 != c[i])
        sum += c[i];
    }
    if (sum / 100 == 0)
      cout << sum + 100 << endl;
    else
      cout << sum << endl;
  }
}
