#include <bits/stdc++.h>
const int MOD = 1000000007;
const int INF = 2002002002;
const long long LLINF = 9009009009009009009;
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int n, m;
  cin >> n >> m;
  vector<int> v(n, INF);
  int s, c;
  for (int i = 0; i < m; ++i) {
    cin >> s >> c;
    s--;
    if (v[s] != INF && v[s] != c) {
      cout << -1 << endl;
      return 0;
    }
    v[s] = c;
  }
  if (n != 0 && v[0] == 0) {
    cout << -1 << endl;
    return 0;
  }
  for (int i = 0; i < n; ++i) {
    if (i != 0 && v[i] == INF) v[i] = 0;
  }
  if (n != 0 && v[0] == INF) v[0] = 1;
  if (n == 0 && v[0] == INF) {
    cout << 0 << endl;
    return 0;
  } else
    for (int i = 0; i < n; ++i) cout << v[i];
  cout << endl;
  return 0;
}
