#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  if (m == 0) {
    cout << "-1" << endl;
    return 0;
  }
  unordered_map<int, int> mp;
  for (int i = 0; i < (m); ++i) {
    int s, c;
    cin >> s >> c;
    s = m - s;
    if (mp[s] != 0 && mp[s] != c) {
      cout << "-1" << endl;
      return 0;
    }
    mp[s] = c;
  }
  int x = 0;
  int b = 1;
  for (int keta = 0; keta < m; keta++) {
    int c = mp[keta];
    x += mp[keta] * b;
    b *= 10;
  }
  int y = 0;
  b = 1;
  for (int keta = 0; keta < n; keta++) {
    y += 9 * b;
    b *= 10;
  }
  if (x > y) {
    cout << "-1" << endl;
    return 0;
  }
  int z = 1;
  for (int keta = 0; keta < n - 1; keta++) z *= 10;
  if (x < z) {
    cout << "-1" << endl;
    return 0;
  }
  cout << x << endl;
  return 0;
}
