#include <bits/stdc++.h>
long long INF = (1ll << 61);
using namespace std;
int main(int argc, char* argv[]) {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int t = 1;
  while (t--) {
    int n, m;
    cin >> n >> m;
    vector<long long> v(n, -1);
    for (int i = 0; i < m; i++) {
      int a, b;
      cin >> a >> b;
      if (v[a - 1] == -1 || v[a - 1] == b)
        v[a - 1] = b;
      else {
        cout << -1 << endl;
        return 0;
      }
    }
    if (v[0] == -1)
      v[0] = 1;
    else if (v[0] == 0) {
      cout << -1 << endl;
      return 0;
    }
    for (int i = 0; i < int((v).size()); i++) cout << (v[i] == -1 ? 0 : v[i]);
    cout << endl;
  }
  return 0;
}
