#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e6 + 5;
int k[4];
int main() {
  int n, m;
  cin >> n >> m;
  int a, b;
  map<int, int> mp;
  for (int i = 1; i <= m; i++) {
    cin >> a >> b;
    if (mp[a])
      k[a] = min(k[a], b);
    else
      k[a] = b;
  }
  if (k[1] == 0) {
    if (n == 1)
      cout << 0 << endl;
    else
      cout << -1 << endl;
  } else {
    for (int i = 1; i <= n; i++) {
      cout << k[i];
    }
    cout << endl;
  }
}
