#include <bits/stdc++.h>
using namespace std;
const unsigned long long int hell = 100005;
unsigned long long int s[6][2];
bool comp(vector<unsigned long long int> a, vector<unsigned long long int> b) {
  return a[0] < b[0];
}
bool pred(vector<unsigned long long int> a, vector<unsigned long long int> b) {
  if (a[0] == b[0])
    return 1;
  else
    return 0;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  unsigned long long int n, m;
  cin >> n >> m;
  vector<vector<unsigned long long int>> v;
  for (unsigned long long int i = 0; i < m; i++) {
    v.push_back(vector<unsigned long long int>());
    for (unsigned long long int j = 0; j < 2; j++) {
      unsigned long long int x;
      cin >> x;
      v[i].push_back(x);
    }
    if (v[i][0] == 1 && v[i][1] == 0 && n != 1) {
      cout << "-1";
      exit(0);
    }
  }
  sort(v.begin(), v.end(), comp);
  for (unsigned long long int i = 0; i < m - 1; i++) {
    for (unsigned long long int j = i + 1; j < m; j++) {
      if (v[i][0] == v[j][0] && v[i][1] != v[j][1]) {
        cout << "-1";
        exit(0);
      }
    }
  }
  v.push_back(vector<unsigned long long int>(2));
  v[m][0] = v[m][1] = -1;
  unsigned long long int ans = 0;
  for (unsigned long long int i = 0; i < m; i++) {
    if (v[i][0] == v[i + 1][0]) continue;
    ans += v[i][1] * pow(10, n - v[i][0]);
  }
  unsigned long long int dig = log10(ans) + 1;
  if (dig < n) {
    ans += pow(10, n - 1);
  }
  cout << ans;
  return 0;
}
