#include <bits/stdc++.h>
using namespace std;
long long gcd(long long a, long long b) {
  if (b == 0) return a;
  return gcd(b, a % b);
}
long long deg(int i) {
  long long ret = 1;
  while (i != 0) {
    if (i / 10 == 0) {
      break;
    }
    i /= 10;
  }
  return i;
}
bool judge(string s) {
  bool ret = false;
  string t = s;
  reverse(t.begin(), t.end());
  if (s == t) {
    ret = true;
  }
  return ret;
}
void solve() {
  int n, m;
  cin >> n >> m;
  vector<pair<int, int>> v;
  int s, c;
  for (int i = 0; i < m; i++) {
    cin >> s >> c;
    v.push_back(make_pair(s, c));
  }
  bool flag = false;
  int co = 0;
  sort(v.begin(), v.end());
  for (int i = 0; i < m; i++) {
    for (int j = i + 1; j < m; j++) {
      if (v[i].first == v[j].first && v[i].second != v[j].second) {
        flag = true;
      }
      if (v[i].first == n) {
        co = 1;
      }
      if (v[i].first == n && v[i].second == 0) {
        flag = true;
      }
    }
  }
  if (c == 0) flag = true;
  if (flag) {
    cout << -1 << endl;
  } else {
    int ans = 0;
    bool d[n];
    for (int i = 0; i < n; i++) d[i] = false;
    for (int i = 0; i < m; i++) {
      if (!d[v[i].first]) {
        d[v[i].first] = true;
        ans += (int)pow(10, n - v[i].first) * v[i].second;
      }
    }
    cout << ans << endl;
  }
}
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  solve();
}
