#include <bits/stdc++.h>
using namespace std;
int main() {
  int N, M;
  cin >> N >> M;
  vector<int> s(M);
  vector<int> c(M);
  vector<int> ans(N, 0);
  int a = 0;
  int b[3] = {100, 10, 1};
  for (int i = 0; i < M; ++i) {
    cin >> s[i] >> c[i];
    if ((N > 1) && ((s[i]) == 1) && (c[i]) == 0) {
      cout << -1 << endl;
      return 0;
    }
    for (int j = 0; j < i; ++j) {
      if ((s[i] == s[j]) && (c[i] != c[j])) {
        cout << -1 << endl;
        return 0;
      }
    }
    ans[s[i] - 1] = c[i];
  }
  if ((N > 1) && (ans[0]) == 0) ans[0] = 1;
  for (int k = N; k != 0; --k) {
    a += ans[k - 1] * b[k - 1];
  }
  cout << a;
  return 0;
}
