#include <bits/stdc++.h>
using namespace std;
long long ans, mx, sum, mn = 1e8;
long long cnt;
long long a[100];
int main() {
  long long n, m;
  cin >> n >> m;
  vector<pair<long long, long long> > v;
  for (long long i = 0; i < m; i++) {
    long long a, b;
    cin >> a >> b;
    v.push_back(make_pair(a - 1, b));
  }
  sort(v.begin(), v.end());
  for (long long i = 0; i < m; i++) {
    a[v[i].first] = v[i].second;
  }
  if (v[m - 1].first != (n - 1))
    cout << -1;
  else if (a[v[m - 1].first] == 0)
    cout << -1;
  else {
    for (long long i = 0; i < m; i++) cout << a[i];
  }
}
