#include <bits/stdc++.h>
using namespace std;
using ll = long long;
constexpr ll mod = 1000000007;
constexpr int inf = 1000000000;
constexpr ll linf = 1000000000000000000;
int main() {
  int n, m;
  cin >> n >> m;
  int v[n];
  fill(v, v + n, -1);
  bool can = true;
  for (int i = 0; i < m; ++i) {
    int s, c;
    cin >> s >> c;
    --s;
    if (v[s] == -1)
      v[s] = c;
    else if (v[s] != c) {
      can = false;
    }
  }
  if (v[0] == 0) {
    can = false;
  }
  if (!can) {
    cout << -1 << endl;
    return 0;
  }
  if (v[0] == -1) v[0] = 1;
  for (int i = 0; i < n; ++i) {
    if (v[i] == -1) {
      cout << 0;
    } else {
      cout << v[i];
    }
  }
  cout << endl;
}
