#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  cout.tie(nullptr);
  int n, m;
  cin >> n >> m;
  int a[n];
  memset(a, -1, sizeof(a));
  for (int i = 0; i < m; ++i) {
    int s, c;
    cin >> s >> c;
    if (a[s - 1] != -1 && a[s - 1] != c) {
      cout << -1;
      return 0;
    }
    a[s - 1] = c;
  }
  if (a[0] == 0 && n != 1) return cout << -1, 0;
  for (int i = 0; i < n; ++i) {
    if (a[i] == -1) a[i] = 0;
    cout << a[i];
  }
  cout << endl;
  return 0;
}
