#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL), cout.tie(NULL);
  long long int n, m, x, y;
  map<long long int, set<long long int>> z;
  cin >> n >> m;
  for (int i = 0; i < m; i++) {
    cin >> x >> y;
    z[x].insert(y);
  }
  for (auto x : z)
    if (x.second.size() > 1) {
      cout << -1;
      return 0;
    }
  vector<long long int> num;
  for (int i = 1; i < n + 1; i++)
    if (z[i].size() == 0)
      num.push_back(0LL);
    else
      num.push_back((*(z[i].begin())));
  if (n == 1)
    cout << num[0];
  else if (num[0] == 0) {
    cout << -1;
    return 0;
  } else
    for (auto l : num) cout << l;
  return 0;
}
