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