#include <bits/stdc++.h>
using namespace std;
int main() {
  long long n, m, ans = 0;
  bool flag = true;
  cin >> n >> m;
  if (m > 0) {
    vector<vector<long long>> s(m, vector<long long>(2));
    for (long long i = 0; i < m; i++) cin >> s[i][0] >> s[i][1];
    sort(s.begin(), s.end());
    for (long long i = 0; i < s.size() - 1; i++)
      if (s[i][0] == s[i + 1][0] && s[i][1] == s[i + 1][1])
        s.erase(s.begin() + i);
    if (s.size() == 1) {
      if (s[0][0] == 1 && s[0][1] == 0) flag = false;
    } else {
      for (long long i = 0; i < s.size() - 1; i++) {
        if (s[i][0] == s[i + 1][0] && s[i][1] == s[i + 1][1])
          continue;
        else if ((s[i][0] == s[i + 1][0]) || (s[i][0] == 1 && s[i][1] == 0))
          flag = false;
      }
    }
    if (flag) {
      for (long long i = 0; i < s.size(); i++) {
        long long buf = 1;
        for (long long j = 0; j < n - s[i][0]; j++) buf *= 10;
        ans += buf * s[i][1];
      }
      cout << ans << endl;
    } else
      cout << "-1" << endl;
  } else
    cout << "0" << endl;
}
