#include <bits/stdc++.h>
using namespace std;
vector<pair<int, int> > v;
bool operator<(pair<int, int> a, pair<int, int> b) {
  if (a.first != b.first) return a.first < b.first;
  return a.second < b.second;
}
int s[100005];
int main() {
  int n, m;
  cin >> n >> m;
  for (int i = 1; i <= m; i++) {
    int a, b;
    cin >> a >> b;
    v.push_back(make_pair(a, b));
  }
  sort(v.begin(), v.end());
  for (int i = 0; i < v.size() - 1; i++) {
    if (v[i].first == v[i + 1].first && v[i].second != v[i + 1].second) {
      cout << "-1";
      return 0;
    }
    s[v[i].first] = v[i].second;
    s[v[i + 1].first] = v[i + 1].second;
  }
  if (n > 1 && s[1] == 0) {
    cout << "-1";
    return 0;
  }
  for (int i = 1; i <= n; i++) cout << s[i];
  return 0;
}
