#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> as;
  int count = 0;
  for (int i = 0; i < m; i++) {
    cin >> s[i] >> c[i];
    s[i]--;
  }
  int keta = 0;
  for (int i = 0; i < m; i++) {
    if (s[i] == 0 && c[i] == 0) {
      cout << -1 << endl;
      return 0;
    }
    if (s[i] == 0) keta++;
    for (int j = i + 1; j < m; j++) {
      if (s[i] == s[j]) {
        if (c[i] != c[j]) {
          cout << -1 << endl;
          return 0;
        }
        as.push_back(s[j]);
        as.push_back(c[j]);
        count++;
        if (s[i] == 0) keta--;
      }
    }
  }
  if (keta > 1) {
    cout << -1 << endl;
    return 0;
  } else if (keta == 0) {
    cout << -1 << endl;
    return 0;
  }
  int ans = 0;
  for (int i = 0; i < m; i++) {
    ans += c[i] * pow(10, n - 1 - s[i]);
  }
  for (int i = 0; i < count; i++) {
    ans -= as[i * 2 + 1] * pow(10, n - 1 - as[i * 2]);
  }
  cout << ans << endl;
  return 0;
}
