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