#include <bits/stdc++.h>
using ll = long long;
using namespace std;
int main() {
  int n, m;
  bool a = true;
  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 j = 0; j < (i); j++) {
      if (s[i] == s[j]) {
        if (c[i] != c[j]) {
          a = false;
        } else {
          s[i] = -1;
        }
      }
    }
    if (s[i] == 1 && c[i] == 0) {
      a = false;
    }
  }
  vector<int> ans(m);
  int b = 0;
  if (a) {
    for (int i = 0; i < (m); i++) {
      if (s[i] != -1) {
        ans[i] = c[i] * pow(10, m - s[i]);
      }
      b += ans[i];
    }
    cout << b;
  } else {
    cout << -1;
  }
  return 0;
}
