#include <bits/stdc++.h>
using namespace std;
int keta(int x) {
  int cnt = 0;
  while (x) {
    cnt++;
    x /= 10;
  }
  return cnt;
}
int main() {
  int n, m;
  cin >> n >> m;
  map<int, int> mp;
  for (int i = 0; i < m; i++) {
    int s, c;
    cin >> s >> c;
    if (mp[s] == 0) {
      mp[s] = c;
    } else {
      if (mp[s] == c)
        continue;
      else
        cout << "-1" << endl;
      return 0;
    }
  }
  int ans = 0;
  for (auto p : mp) {
    ans += p.second * pow(10, n - p.first);
  }
  if (keta(ans) == n) {
    cout << ans << endl;
  } else {
    cout << "-1" << endl;
  }
  return 0;
}
