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