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