#include <bits/stdc++.h>
using namespace std;
const long long int MOD = 1e9 + 7;
const long long int INF = 1e10;
int32_t main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  long long int n, m;
  cin >> n >> m;
  vector<long long int> a(n + 1, -1);
  bool check = true;
  for (long long int i = 0; i < m; i++) {
    long long int x, y;
    cin >> x >> y;
    if (a[x] != -1 && y != a[x]) {
      check = false;
    } else {
      a[x] = y;
    }
  }
  if (a[1] == -1 || a[1] == 0 || !check) {
    cout << -1;
  } else {
    for (long long int i = 1; i <= n; i++) {
      if (a[i] == -1)
        cout << 0;
      else
        cout << a[i];
    }
  }
  return 0;
}
