#include <bits/stdc++.h>
using namespace std;
const int N = 2e3 + 5;
int main() {
  int n, m, a, b, ans = 0, flag = 1;
  cin >> n >> m;
  if (m == 0) {
    if (n == 1)
      cout << 0 << endl;
    else
      cout << pow(10.0, n - 1) << endl;
    return 0;
  }
  map<int, int> mp;
  while (m--) {
    cin >> a >> b;
    if (mp[a] && mp[a] - 1 != b || (a + b == 1 && n != 1)) {
      flag = 0;
      cout << "-1" << endl;
    } else {
      if (!mp[a]) ans += (int)pow(10.0, (double)n - a) * b;
      mp[a] = b + 1;
    }
  }
  if (ans < pow(10.0, n - 1)) ans += pow(10.0, n - 1);
  if (flag) cout << ans << endl;
}
