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