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