#include <bits/stdc++.h>
using namespace std;
void solve() {
  long long n, m;
  cin >> n >> m;
  unordered_map<long long, long long> umap;
  for (long long i = 0; i < m; ++i) {
    long long s, c;
    cin >> s >> c;
    if (umap[s] == c || umap.find(s) == umap.end())
      umap[s] = c;
    else {
      cout << -1;
      return;
    }
  }
  long long cnt = 0;
  for (long long i = 1; i <= n; ++i) {
    if (umap[i] == 0) cnt++;
  }
  if (cnt == n) {
    cout << -1;
    return;
  }
  for (long long i = 1; i <= n; ++i) {
    cout << umap[i];
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  ;
  int t;
  t = 1;
  while (t--) {
    solve();
  }
  return 0;
}
