#include <bits/stdc++.h>
using namespace std;
const long long INF = 1LL << 60;
int main(void) {
  int N, M;
  vector<int> s, c;
  cin >> N >> M;
  s.resize(M);
  c.resize(M);
  for (int i = 0; i < M; ++i) {
    cin >> s[i] >> c[i];
    s[i]--;
  }
  vector<int> ans(N);
  vector<bool> seen(N);
  for (int i = 0; i < N; ++i) {
    seen[i] = false;
    ans[i] = 0;
  }
  for (int i = 0; i < M; ++i) {
    if (!seen[s[i]]) {
      seen[s[i]] = true;
      ans[s[i]] = c[i];
    } else {
      if (ans[s[i]] != c[i]) {
        cout << -1 << endl;
        return 0;
      }
    }
  }
  if (ans[0] == 0 && N >= 2) {
    if (M != 1)
      ans[0] = 1;
    else {
      cout << -1 << endl;
      return 0;
    }
  }
  for (int i = 0; i < N; ++i) cout << ans[i];
  cout << endl;
  return 0;
}
