#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int n, m;
  cin >> n >> m;
  vector<int> v(n + 1, -1);
  for (long long int(i) = (0); (i) < (m); (i)++) {
    int pos, num;
    cin >> pos >> num;
    if (v[pos] == -1) {
      v[pos] = num;
    } else if (v[pos] != num) {
      cout << -1;
      return 0;
    }
  }
  if (v[1] == 0 && n > 1) {
    cout << -1;
    return 0;
  } else if (v[1] == 0 && n == 1) {
    cout << 0;
    return 0;
  }
  for (long long int(i) = (1); (i) < (n + 1); (i)++) {
    if (v[i] == -1) v[i] = 9;
  }
  for (long long int(i) = (1); (i) < (n + 1); (i)++) cout << v[i];
  return 0;
}
