#include <bits/stdc++.h>
using namespace std;
const long long N = (1 << 10);
long long a[N];
long long c[N];
long long lft[N];
long long ryt[N];
long long n, m;
string s;
void read() {
  long long i, j, k;
  cin >> n >> m;
  for (i = 1; i < n + 1; i++) cin >> a[i];
  for (i = 1; i < m + 1; i++) cin >> lft[i] >> ryt[i];
}
void solve() {
  long long i, j, k;
  vector<long long> ans;
  long long range = 0;
  for (i = 1; i < n + 1; i++) {
    for (j = 1; j < n + 1; j++) c[j] = 0;
    vector<long long> T;
    for (j = 1; j < m + 1; j++)
      if (i >= lft[j] and i <= ryt[j]) {
        c[lft[j]] -= 1;
        c[ryt[j] + 1] += 1;
        T.push_back(j);
      }
    long long low = a[1] + c[1];
    long long high = a[1] + c[1];
    long long count = 0;
    for (j = 1; j < n + 1; j++) {
      count += c[j];
      low = min(low, a[j] + count);
      high = max(high, a[j] + count);
    }
    if (high - low > range) ans = T;
    range = max(range, high - low);
  }
  cout << range << "\n";
  cout << ans.size() << "\n";
  for (i = 0; i < ans.size(); i++) cout << ans[i] << " ";
}
int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  read();
  solve();
}
