#include <bits/stdc++.h>
using namespace std;
const double pi = 3.1415926535;
const long long mod = 1000000007;
int main() {
  int n, m;
  int ans = 0;
  vector<int> v(n, -1);
  cin >> n >> m;
  for (int i = 0; i < m; i++) {
    int x = 0;
    int y = 0;
    cin >> x >> y;
    x--;
    if (n != 1 && x == 0 && y == 0) {
      ans = -1;
      break;
    }
    if (v[x] == -1 || v[x] == y) {
      v[x] = y;
    } else {
      ans = -1;
      break;
    }
  }
  if (ans) {
    cout << ans << endl;
    return 0;
  }
  for (int j = 0; j < n; j++) {
    if (v[j] < 0) v[j] = 0;
    if (v[0] == 0) v[0] = 1;
    cout << v[j];
  }
}
