#include <bits/stdc++.h>
using namespace std;
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int N, M;
  cin >> N >> M;
  vector<int> s(M);
  vector<int> c(M);
  for (int i = 0; i < (M); ++i) {
    int n, m;
    cin >> n >> m;
    s[i] = n, c[i] = m;
  }
  map<int, int> mp;
  for (int i = 0; i < (M); ++i) {
    if (mp.find(s[i]) != mp.end()) {
      if (mp[s[i]] != c[i]) {
        cout << -1 << endl;
        return 0;
      }
    } else {
      mp[s[i]] = c[i];
    }
  }
  vector<int> ans(N);
  for (int i = 0; i < N; i++) {
    ans[s[i] - 1] = c[i];
  }
  if (ans[0] == 0 && N >= 2) {
    cout << -1 << endl;
    return 0;
  }
  for (auto a : ans) {
    cout << a;
  }
}
