#include <bits/stdc++.h>
using namespace std;
long long ar[101];
void solve() {
  long long n, m;
  cin >> n >> m;
  for (long long i = 0; i < (n + 1); ++i) ar[i] = -1;
  for (long long i = 0; i < (m); ++i) {
    long long x, y;
    cin >> x >> y;
    if (ar[x] != -1 && y != ar[x]) {
      cout << "-1\n";
      return;
    }
    ar[x] = y;
  }
  if (ar[1] > 0) {
    for (long long i = 0; i < (n); ++i)
      cout << (ar[i + 1] == -1 ? 0 : ar[i + 1]);
  } else
    cout << -1;
}
int32_t main() {
  ios::sync_with_stdio(0), cin.tie(NULL), cout.tie(NULL);
  long long t = 1;
  while (t--) {
    solve();
  }
  return 0;
}
