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