#include <bits/stdc++.h>
using namespace std;
const long long INF = (long long)(1e18) + 1;
int main() {
  int n;
  int m;
  cin >> n >> m;
  map<int, int> nums;
  bool flag = false;
  for (int i = 0; i < m; ++i) {
    int a, b;
    cin >> a >> b;
    if (n != 1 && a == 1 && b == 0) {
      flag = true;
    }
    if (nums.count(a) && nums[a] != b) {
      flag = true;
    }
    nums[a] = b;
  }
  if (flag) {
    cout << -1 << endl;
    return 0;
  }
  string ans = "";
  for (int i = 1; i <= n; ++i) {
    if (nums.count(i)) {
      ans += to_string(nums[i]);
    } else if (i == 1 && n != 1) {
      ans += "1";
    } else {
      ans += "0";
    }
  }
  cout << ans[0] << endl;
}
