#include <bits/stdc++.h>
using namespace std;
inline long long mod(long long a, long long m) { return (a % m + m) % m; }
template <class T>
bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T>
bool chmin(T &a, const T &b) {
  if (b < a) {
    a = b;
    return 1;
  }
  return 0;
}
int n, m, a[10], c[10];
pair<long long, long long> p[10];
void solve() {
  cin >> n >> m;
  for (int i = 0; i < m; i++) {
    cin >> a[i] >> c[i];
    p[i] = pair<long long, long long>(a[i] - 1, c[i]);
  }
  sort(p, p + m);
  vector<int> s(n, 0);
  for (int i = 0; i < m; i++) {
    int x = p[i].first, y = p[i].second;
    if (s[x] != 0 && s[x] != y) {
      cout << -1 << endl;
      return;
    }
    s[x] = y;
  }
  if (s[0] == 0) {
    cout << -1 << endl;
    return;
  }
  for (int i = 0; i < n; i++) {
    cout << s[i];
  }
  cout << endl;
}
int main() {
  std::cin.tie(0);
  std::ios::sync_with_stdio(false);
  int t = 1;
  while (t--) {
    solve();
  }
  return 0;
}
