#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1e9 + 7;
const double PI = 2 * acos(0.0);
int main() {
  long long n, m, flag = 0;
  long long arr[3];
  arr[0] = 0, arr[1] = 0, arr[2] = 0;
  cin >> n >> m;
  map<long long, long long> mp;
  while (m--) {
    long long x, y;
    cin >> x >> y;
    if (x == 1 and y == 0 and n > 1)
      flag = 1;
    else if (arr[x - 1] != 0 and arr[x - 1] != y)
      flag = 1;
    else {
      arr[x - 1] = y;
    }
  }
  if (flag)
    cout << -1 << endl;
  else {
    for (int i = 0; i < n; i++) {
      cout << arr[i];
    }
  }
}
