#include <bits/stdc++.h>
using namespace std;
const int MaxN = 200005;
int mcd(int a, int b) {
  if (a == 0) return b;
  return mcd(b % a, a);
}
int vis[10];
int main() {
  long long int N, K, i, j, s = 0, p, q;
  cin >> N >> K;
  for (i = 0; i <= N; i++) vis[i] = -1;
  for (i = 0; i < K; i++) {
    cin >> p >> q;
    if (vis[p] == -1) {
      vis[p] = q;
    } else {
      if (vis[p] != q) {
        cout << "-1";
        return 0;
      }
    }
  }
  if (N == 1 && vis[1] == -1) {
    cout << "0";
    return 0;
  }
  if (N == 1) {
    cout << vis[1];
    return 0;
  }
  if (vis[1] == 0) {
    cout << "-1";
    return 0;
  }
  if (vis[1] == -1) vis[0] = 1;
  for (i = 1; i <= N; i++) {
    if (vis[i] == -1)
      cout << "0";
    else
      cout << vis[i];
  }
}
