#include <bits/stdc++.h>
using namespace std;
const long long inf = 1e18 + 1;
const long long limit = 1e9;
int main() {
  int n, m;
  cin >> n >> m;
  vector<int> v(n + 1, -1);
  bool ok = true;
  for (int i = 0; i < m; i++) {
    int s, c;
    cin >> s >> c;
    if (v[s] == -1) {
      v[s] = c;
    } else if (v[s] != -1 && v[s] != c)
      ok = false;
  }
  if (v[1] == 0) ok = false;
  if (n == 1 && ok) {
    if (v[1] == -1) v[1] = 0;
    cout << v[1] << "\n";
  } else if (ok) {
    if (v[1] == -1) v[1] = 1;
    cout << v[1];
    for (int i = 2; i <= n; i++) {
      if (v[i] == -1) v[i] = 0;
      cout << v[i];
    }
    cout << "\n";
  } else
    cout << -1 << "\n";
}
