#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m, s, c;
  cin >> n >> m;
  vector<int> a(n);
  for (int i = 0; i < (n); ++i) a[i] = -1;
  for (int i = 0; i < (m); ++i) {
    cin >> s >> c;
    if ((s == 1 && c == 0) || (a[s - 1] != -1 && a[s - 1] != c))
      cout << -1 << endl, exit(0);
    a[s - 1] = c;
  }
  for (int i = 0; i < (n); ++i) cout << (a[i] == -1 ? (i == 0) : a[i]);
}
