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